You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by st...@locus.apache.org on 2000/05/16 22:19:31 UTC

cvs commit: apache-2.0/src/modules/standard mod_cgi.c mod_include.c

stoddard    00/05/16 13:19:30

  Modified:    src/modules/standard mod_cgi.c mod_include.c
  Log:
  Update a couple of modules to use ap_stat() rather than stat().
  
  Revision  Changes    Path
  1.37      +9 -9      apache-2.0/src/modules/standard/mod_cgi.c
  
  Index: mod_cgi.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/standard/mod_cgi.c,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- mod_cgi.c	2000/04/18 00:08:30	1.36
  +++ mod_cgi.c	2000/05/16 20:19:29	1.37
  @@ -175,15 +175,15 @@
   			   int show_errno, char *error)
   {
       ap_file_t *f = NULL;
  -    struct stat finfo;
  +    ap_finfo_t finfo;
       char time_str[AP_CTIME_LEN];
   
       ap_log_rerror(APLOG_MARK, show_errno|APLOG_ERR, errno, r, 
   		"%s: %s", error, r->filename);
   
       if (!conf->logname ||
  -	((stat(ap_server_root_relative(r->pool, conf->logname), &finfo) == 0)
  -	 &&   (finfo.st_size > conf->logbytes)) ||
  +        ((ap_stat(&finfo, ap_server_root_relative(r->pool, conf->logname), r->pool) == APR_SUCCESS)
  +         &&  (finfo.size > conf->logbytes)) ||
             (ap_open(&f, ap_server_root_relative(r->pool, conf->logname),
                      APR_APPEND, APR_OS_DEFAULT, r->pool) != APR_SUCCESS)) {
   	return ret;
  @@ -210,12 +210,12 @@
       char argsbuffer[HUGE_STRING_LEN];
       ap_file_t *f = NULL;
       int i;
  -    struct stat finfo;
  +    ap_finfo_t finfo;
       char time_str[AP_CTIME_LEN];
   
       if (!conf->logname ||
  -	((stat(ap_server_root_relative(r->pool, conf->logname), &finfo) == 0)
  -	 &&   (finfo.st_size > conf->logbytes)) ||
  +        ((ap_stat(&finfo, ap_server_root_relative(r->pool, conf->logname), r->pool) == APR_SUCCESS)
  +         &&  (finfo.size > conf->logbytes)) ||
            (ap_open(&f, ap_server_root_relative(r->pool, conf->logname),
                     APR_APPEND, APR_OS_DEFAULT, r->pool) != APR_SUCCESS)) {
   	/* Soak up script output */
  @@ -494,12 +494,12 @@
   #if defined(OS2) || defined(WIN32)
       /* Allow for cgi files without the .EXE extension on them under OS/2 */
       if (r->finfo.protection == 0) {
  -        struct stat statbuf;
  +        ap_finfo_t finfo;
           char *newfile;
   
           newfile = ap_pstrcat(r->pool, r->filename, ".EXE", NULL);
  -
  -        if ((stat(newfile, &statbuf) != 0) || (!S_ISREG(statbuf.st_mode))) {
  +        if ((ap_stat(&finfo, newfile, r->pool) != APR_SUCCESS) || 
  +            (finfo.filetype != APR_REG)) {
               return log_scripterror(r, conf, NOT_FOUND, 0,
                                      "script not found or unable to stat");
           } else {
  
  
  
  1.29      +1 -1      apache-2.0/src/modules/standard/mod_include.c
  
  Index: mod_include.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/standard/mod_include.c,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- mod_include.c	2000/05/16 01:59:07	1.28
  +++ mod_include.c	2000/05/16 20:19:29	1.29
  @@ -1129,7 +1129,7 @@
   
           if (rr->status == HTTP_OK && rr->finfo.protection != 0) {
               memcpy((char *) finfo, (const char *) &rr->finfo,
  -                   sizeof(struct stat));
  +                   sizeof(rr->finfo));
               ap_destroy_sub_req(rr);
               return 0;
           }
  
  
  

sizeof stylistic convention (was: cvs commit: ... mod_cgi.c mod_include.c)

Posted by Greg Stein <gs...@lyra.org>.
On 16 May 2000 stoddard@locus.apache.org wrote:
>...
>   --- mod_include.c	2000/05/16 01:59:07	1.28
>   +++ mod_include.c	2000/05/16 20:19:29	1.29
>   @@ -1129,7 +1129,7 @@
>    
>            if (rr->status == HTTP_OK && rr->finfo.protection != 0) {
>                memcpy((char *) finfo, (const char *) &rr->finfo,
>   -                   sizeof(struct stat));
>   +                   sizeof(rr->finfo));
>                ap_destroy_sub_req(rr);
>                return 0;
>            }

This is a stylistic convention that I'd like to call attention to. When
doing a sizeof(), it is "best" to do a sizeof of the target variable or
expression, rather than hard-coding a type. When the type changes, then
the sizeof doesn't need to be maintained.

Some examples:

  p = malloc(sizeof(*p));      // be careful; don't write sizeof(p) ! :-)
  memcpy(p1, p2, sizeof(p1));  // or sizeof(p2)


Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/