From: Sascha Schumann Date: Thu, 10 Jan 2002 07:21:57 +0000 (+0000) Subject: Add three-parameter touch() which enables users to set X-Git-Tag: PRE_ISSET_PATCH~230 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=edfd6d0988789752c3b1e90f6b4ef3ea07393d5a;p=php Add three-parameter touch() which enables users to set mtime/atime to different values. --- diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c index 525ebfb3f5..d1b17b726a 100644 --- a/ext/standard/filestat.c +++ b/ext/standard/filestat.c @@ -465,12 +465,12 @@ PHP_FUNCTION(chmod) } /* }}} */ -/* {{{ proto bool touch(string filename [, int time]) +/* {{{ proto bool touch(string filename [, int time [, int atime]]) Set modification time of file */ PHP_FUNCTION(touch) { #if HAVE_UTIME - pval **filename, **filetime; + pval **filename, **filetime, **fileatime; int ret; struct stat sb; FILE *file; @@ -484,8 +484,7 @@ PHP_FUNCTION(touch) php_error(E_WARNING, "unable to emalloc memory for changing time"); return; } - newtime->actime = time(NULL); - newtime->modtime = newtime->actime; + 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)); @@ -494,7 +493,16 @@ PHP_FUNCTION(touch) return; } convert_to_long_ex(filetime); - newtime->actime = Z_LVAL_PP(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); newtime->modtime = Z_LVAL_PP(filetime); } else { WRONG_PARAM_COUNT;