diff options
author | Anatol Belski <ab@php.net> | 2014-11-10 09:14:15 +0100 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2014-11-10 10:58:19 +0100 |
commit | 999d387bf8183e6ddb755dd3e6e4454044c28641 (patch) | |
tree | 06fc80635c1bfc68ecebeef44295129ade39a3cf /TSRM | |
parent | 249e3de5da9cc7b5dc5bde81ad8ac9e8034349d4 (diff) | |
download | php-git-999d387bf8183e6ddb755dd3e6e4454044c28641.tar.gz |
move these functions to the appropriate place
and include the necessary header
Diffstat (limited to 'TSRM')
-rw-r--r-- | TSRM/tsrm_win32.c | 48 | ||||
-rw-r--r-- | TSRM/tsrm_win32.h | 3 |
2 files changed, 51 insertions, 0 deletions
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 <windows.h> +#if HAVE_UTIME +# include <sys/utime.h> +#endif struct ipc_perm { int key; |