]> granicus.if.org Git - php/commitdiff
- #45985, touch on opened file raises a warning
authorPierre Joye <pajoye@php.net>
Thu, 4 Sep 2008 08:03:31 +0000 (08:03 +0000)
committerPierre Joye <pajoye@php.net>
Thu, 4 Sep 2008 08:03:31 +0000 (08:03 +0000)
TSRM/tsrm_virtual_cwd.c
ext/standard/tests/file/bug45985.phpt [new file with mode: 0644]

index 2083fff00fc34c41525ad59022c5a973b6f47d60..516ecbdf6a073257d1f508f2bf66b5f128690200 100644 (file)
@@ -1032,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 (file)
index 0000000..1b98da2
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Bug #35740 (touch() opened file raises a warning)
+--FILE--
+<?php
+$file = __DIR__ . '/' . '__tmp_35740.dat';
+file_put_contents($file, 'test');
+$f = fopen($file, 'r');
+touch($file);
+fclose($f);
+@unlink($file);
+echo "ok";
+?>
+--EXPECT--
+ok