From: Anatol Belski Date: Mon, 10 Nov 2014 08:14:15 +0000 (+0100) Subject: move these functions to the appropriate place X-Git-Tag: PRE_NATIVE_TLS_MERGE~130^2~34^2~1^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=999d387bf8183e6ddb755dd3e6e4454044c28641;p=php move these functions to the appropriate place and include the necessary header --- diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c index 9936320a95..7194dffd61 100644 --- a/TSRM/tsrm_win32.c +++ b/TSRM/tsrm_win32.c @@ -722,4 +722,52 @@ TSRM_API char *realpath(char *orig_path, char *buffer) return buffer; } +#if HAVE_UTIME +static zend_always_inline void UnixTimeToFileTime(time_t t, LPFILETIME pft) /* {{{ */ +{ + // Note that LONGLONG is a 64-bit value + LONGLONG ll; + + ll = Int32x32To64(t, 10000000) + 116444736000000000; + pft->dwLowDateTime = (DWORD)ll; + pft->dwHighDateTime = ll >> 32; +} +/* }}} */ + +TSRM_API int win32_utime(const char *filename, struct utimbuf *buf) /* {{{ */ +{ + FILETIME mtime, atime; + HANDLE hFile; + + hFile = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, + OPEN_ALWAYS, FILE_FLAG_BACKUP_SEMANTICS, NULL); + + /* OPEN_ALWAYS mode sets the last error to ERROR_ALREADY_EXISTS but + the CreateFile operation succeeds */ + if (GetLastError() == ERROR_ALREADY_EXISTS) { + SetLastError(0); + } + + if ( hFile == INVALID_HANDLE_VALUE ) { + return -1; + } + + if (!buf) { + SYSTEMTIME st; + GetSystemTime(&st); + SystemTimeToFileTime(&st, &mtime); + atime = mtime; + } else { + UnixTimeToFileTime(buf->modtime, &mtime); + UnixTimeToFileTime(buf->actime, &atime); + } + if (!SetFileTime(hFile, NULL, &atime, &mtime)) { + CloseHandle(hFile); + return -1; + } + CloseHandle(hFile); + return 1; +} +/* }}} */ +#endif #endif diff --git a/TSRM/tsrm_win32.h b/TSRM/tsrm_win32.h index 5933b54ddf..beff1e88cf 100644 --- a/TSRM/tsrm_win32.h +++ b/TSRM/tsrm_win32.h @@ -23,6 +23,9 @@ #include "TSRM.h" #include +#if HAVE_UTIME +# include +#endif struct ipc_perm { int key; diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c index 385df393bf..f8b42b1596 100644 --- a/Zend/zend_virtual_cwd.c +++ b/Zend/zend_virtual_cwd.c @@ -1540,55 +1540,6 @@ CWD_API int virtual_access(const char *pathname, int mode TSRMLS_DC) /* {{{ */ /* }}} */ #if HAVE_UTIME -#ifdef TSRM_WIN32 -static void UnixTimeToFileTime(time_t t, LPFILETIME pft) /* {{{ */ -{ - // Note that LONGLONG is a 64-bit value - LONGLONG ll; - - ll = Int32x32To64(t, 10000000) + 116444736000000000; - pft->dwLowDateTime = (DWORD)ll; - pft->dwHighDateTime = ll >> 32; -} -/* }}} */ - -TSRM_API int win32_utime(const char *filename, struct utimbuf *buf) /* {{{ */ -{ - FILETIME mtime, atime; - HANDLE hFile; - - hFile = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, - OPEN_ALWAYS, FILE_FLAG_BACKUP_SEMANTICS, NULL); - - /* OPEN_ALWAYS mode sets the last error to ERROR_ALREADY_EXISTS but - the CreateFile operation succeeds */ - if (GetLastError() == ERROR_ALREADY_EXISTS) { - SetLastError(0); - } - - if ( hFile == INVALID_HANDLE_VALUE ) { - return -1; - } - - if (!buf) { - SYSTEMTIME st; - GetSystemTime(&st); - SystemTimeToFileTime(&st, &mtime); - atime = mtime; - } else { - UnixTimeToFileTime(buf->modtime, &mtime); - UnixTimeToFileTime(buf->actime, &atime); - } - if (!SetFileTime(hFile, NULL, &atime, &mtime)) { - CloseHandle(hFile); - return -1; - } - CloseHandle(hFile); - return 1; -} -/* }}} */ -#endif - CWD_API int virtual_utime(const char *filename, struct utimbuf *buf TSRMLS_DC) /* {{{ */ { cwd_state new_state;