Browse Source

Fixed bug #16861.

touch sets wrong atime or mtime when they are not specified.
touch silently failed when HAVE_UTIME is not defined.
(This needs more consideration. Which platform does not support it?)
# Derick, after HAVE_UTIME issue is resovled, this should be merged.
# or we can just merge 1st problem for now.
experimental/new_ui_api
Yasuo Ohgaki 25 years ago
parent
commit
6cc8919dc4
  1. 2
      ext/standard/basic_functions.c
  2. 12
      ext/standard/filestat.c
  3. 2
      ext/standard/php_filestat.h

2
ext/standard/basic_functions.c

@ -680,7 +680,9 @@ function_entry basic_functions[] = {
PHP_FE(chown, NULL)
PHP_FE(chgrp, NULL)
PHP_FE(chmod, NULL)
#if HAVE_UTIME
PHP_FE(touch, NULL)
#endif
PHP_FE(clearstatcache, NULL)
PHP_FE(disk_total_space, NULL)
PHP_FE(disk_free_space, NULL)

12
ext/standard/filestat.c

@ -465,17 +465,17 @@ PHP_FUNCTION(chmod)
}
/* }}} */
#if HAVE_UTIME
/* {{{ proto bool touch(string filename [, int time [, int atime]])
Set modification time of file */
PHP_FUNCTION(touch)
{
#if HAVE_UTIME
pval **filename, **filetime, **fileatime;
int ret;
struct stat sb;
FILE *file;
struct utimbuf newtimebuf;
struct utimbuf *newtime = &newtimebuf;
struct utimbuf *newtime = NULL;
int ac = ZEND_NUM_ARGS();
if (ac == 1 && zend_get_parameters_ex(1, &filename) != FAILURE) {
@ -483,9 +483,12 @@ PHP_FUNCTION(touch)
newtime->modtime = newtime->actime = time(NULL);
#endif
} else if (ac == 2 && zend_get_parameters_ex(2, &filename, &filetime) != FAILURE) {
newtime = &newtimebuf;
convert_to_long_ex(filetime);
newtime->actime = time(NULL);
newtime->modtime = newtime->actime = Z_LVAL_PP(filetime);
} else if (ac == 3 && zend_get_parameters_ex(3, &filename, &filetime, &fileatime) != FAILURE) {
newtime = &newtimebuf;
convert_to_long_ex(fileatime);
convert_to_long_ex(filetime);
newtime->actime = Z_LVAL_PP(fileatime);
@ -519,12 +522,11 @@ PHP_FUNCTION(touch)
if (ret == -1) {
php_error(E_WARNING, "utime failed: %s", strerror(errno));
RETURN_FALSE;
} else {
RETURN_TRUE;
}
#endif
RETURN_TRUE;
}
/* }}} */
#endif
/* {{{ proto void clearstatcache(void)
Clear file stat cache */

2
ext/standard/php_filestat.h

@ -48,7 +48,9 @@ PHP_FUNCTION(disk_free_space);
PHP_FUNCTION(chown);
PHP_FUNCTION(chgrp);
PHP_FUNCTION(chmod);
#if HAVE_UTIME
PHP_FUNCTION(touch);
#endif
PHP_FUNCTION(clearstatcache);
#define MAKE_LONG_ZVAL_INCREF(name, val)\

Loading…
Cancel
Save