From 5ec35396e0ed26cfc7c4856e7ffced4cac75003c Mon Sep 17 00:00:00 2001 From: Pierre Joye Date: Thu, 4 Sep 2008 08:05:27 +0000 Subject: - MFH: #45985, touch on opened file raises a warning --- TSRM/tsrm_virtual_cwd.c | 11 ++++++++--- ext/standard/tests/file/bug45985.phpt | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 ext/standard/tests/file/bug45985.phpt diff --git a/TSRM/tsrm_virtual_cwd.c b/TSRM/tsrm_virtual_cwd.c index bf3860547e..edbb9d8b07 100644 --- a/TSRM/tsrm_virtual_cwd.c +++ b/TSRM/tsrm_virtual_cwd.c @@ -818,7 +818,6 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func } #endif - add_slash = (use_realpath != CWD_REALPATH) && path_length > 0 && IS_SLASH(resolved_path[path_length-1]); t = CWDG(realpath_cache_ttl) ? 0 : -1; path_length = tsrm_realpath_r(resolved_path, start, path_length, &ll, &t, use_realpath, 0, NULL TSRMLS_CC); @@ -1033,8 +1032,14 @@ static int win32_utime(const char *filename, struct utimbuf *buf) /* {{{ */ BOOL f; HANDLE hFile; - hFile = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, - OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + 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; diff --git a/ext/standard/tests/file/bug45985.phpt b/ext/standard/tests/file/bug45985.phpt new file mode 100644 index 0000000000..1b98da21aa --- /dev/null +++ b/ext/standard/tests/file/bug45985.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #35740 (touch() opened file raises a warning) +--FILE-- + +--EXPECT-- +ok -- cgit v1.2.1