cvs: php4 /ext/standard filestat.c

From: Date: Thu, 10 Jan 2002 07:25:00 +0000
Subject: cvs: php4 /ext/standard filestat.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-9025@lists.php.net to get a copy of this message
sas Thu Jan 10 02:25:00 2002 EDT Modified files: /php4/ext/standard filestat.c Log: (PHP touch) Operate on a stack buffer.. no need for allocating newtime on the heap. Index: php4/ext/standard/filestat.c diff -u php4/ext/standard/filestat.c:1.87 php4/ext/standard/filestat.c:1.88 --- php4/ext/standard/filestat.c:1.87 Thu Jan 10 02:21:57 2002 +++ php4/ext/standard/filestat.c Thu Jan 10 02:25:00 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: filestat.c,v 1.87 2002/01/10 07:21:57 sas Exp $ */ +/* $Id: filestat.c,v 1.88 2002/01/10 07:25:00 sas Exp $ */ #include "php.h" #include "safe_mode.h" @@ -474,32 +474,18 @@ int ret; struct stat sb; FILE *file; - struct utimbuf *newtime = NULL; + struct utimbuf newtimebuf; + struct utimbuf *newtime = &newtimebuf; int ac = ZEND_NUM_ARGS(); if (ac == 1 && zend_get_parameters_ex(1, &filename) != FAILURE) { #ifndef HAVE_UTIME_NULL - newtime = (struct utimbuf *)emalloc(sizeof(struct utimbuf)); - if (!newtime) { - php_error(E_WARNING, "unable to emalloc memory for changing time"); - return; - } newtime->modtime = newtime->actime = time(NULL); #endif } else if (ac == 2 && zend_get_parameters_ex(2, &filename, &filetime) != FAILURE) { - newtime = (struct utimbuf *)emalloc(sizeof(struct utimbuf)); - if (!newtime) { - php_error(E_WARNING, "unable to emalloc memory for changing time"); - return; - } convert_to_long_ex(filetime); newtime->modtime = newtime->actime = Z_LVAL_PP(filetime); } else if (ac == 3 && zend_get_parameters_ex(3, &filename, &filetime, &fileatime) != FAILURE) { - newtime = (struct utimbuf *)emalloc(sizeof(struct utimbuf)); - if (!newtime) { - php_error(E_WARNING, "unable to emalloc memory for changing time"); - return; - } convert_to_long_ex(fileatime); convert_to_long_ex(filetime); newtime->actime = Z_LVAL_PP(fileatime); @@ -510,15 +496,11 @@ convert_to_string_ex(filename); if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - if (newtime) efree(newtime); RETURN_FALSE; } /* Check the basedir */ if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) { - if (newtime) { - efree(newtime); - } RETURN_FALSE; } @@ -528,14 +510,12 @@ file = VCWD_FOPEN(Z_STRVAL_PP(filename), "w"); if (file == NULL) { php_error(E_WARNING, "unable to create file %s because %s", Z_STRVAL_PP(filename), strerror(errno)); - if (newtime) efree(newtime); RETURN_FALSE; } fclose(file); } ret = VCWD_UTIME(Z_STRVAL_PP(filename), newtime); - if (newtime) efree(newtime); if (ret == -1) { php_error(E_WARNING, "utime failed: %s", strerror(errno)); RETURN_FALSE;

« previous php.cvs (#9025) next »