From: Sara Golemon Date: Wed, 21 Jul 2004 04:37:47 +0000 (+0000) Subject: Add MTDM support to ftp_fopen_wrapper::url_stat() X-Git-Tag: PRE_ZEND_VM_DISPATCH_PATCH~415 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e5ed53b00a281932957efddc9161dce90b451c0a;p=php Add MTDM support to ftp_fopen_wrapper::url_stat() --- diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c index 15e6c64385..3ef9c117fd 100644 --- a/ext/standard/ftp_fopen_wrapper.c +++ b/ext/standard/ftp_fopen_wrapper.c @@ -769,12 +769,58 @@ static int php_stream_ftp_url_stat(php_stream_wrapper *wrapper, char *url, int f ssb->sb.st_size = atoi(tmp_line + 4); } + php_stream_write_string(stream, "MDTM "); + if (resource->path != NULL) { + php_stream_write_string(stream, resource->path); + } else { + php_stream_write_string(stream, "/"); + } + php_stream_write_string(stream, "\r\n"); + result = GET_FTP_RESULT(stream); + if (result == 213) { + char *p = tmp_line + 4; + int n; + struct tm tm, tmbuf, *gmt; + time_t stamp; + + while (p - tmp_line < sizeof(tmp_line) && !isdigit(*p)) { + p++; + } + + if (p - tmp_line > sizeof(tmp_line)) { + goto mdtm_error; + } + + n = sscanf(p, "%4u%2u%2u%2u%2u%2u", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec); + if (n != 6) { + goto mdtm_error; + } + + tm.tm_year -= 1900; + tm.tm_mon--; + tm.tm_isdst = -1; + + /* figure out the GMT offset */ + stamp = time(NULL); + gmt = php_gmtime_r(&stamp, &tmbuf); + gmt->tm_isdst = -1; + + /* apply the GMT offset */ + tm.tm_sec += stamp - mktime(gmt); + tm.tm_isdst = gmt->tm_isdst; + + ssb->sb.st_mtime = mktime(&tm); + } else { + /* error or unsupported command */ + mdtm_error: + ssb->sb.st_mtime = -1; + } + ssb->sb.st_ino = 0; /* Unknown values */ ssb->sb.st_dev = 0; ssb->sb.st_uid = 0; ssb->sb.st_gid = 0; ssb->sb.st_atime = -1; - ssb->sb.st_mtime = -1; ssb->sb.st_ctime = -1; ssb->sb.st_nlink = 1; ssb->sb.st_rdev = -1;