]> granicus.if.org Git - php/commitdiff
revisit fix for bug #65272
authorAnatol Belski <ab@php.net>
Sat, 21 Feb 2015 13:10:59 +0000 (14:10 +0100)
committerAnatol Belski <ab@php.net>
Sat, 21 Feb 2015 13:10:59 +0000 (14:10 +0100)
ext/standard/file.c
ext/standard/flock_compat.c

index c15dd505072d0ebcbb660b82f2f1ca53a5d98c98..c2e71d1deaa1f67ab0db85ca52a3f9d0e54410ee 100644 (file)
@@ -356,11 +356,7 @@ PHP_FUNCTION(flock)
        /* flock_values contains all possible actions if (operation & 4) we won't block on the lock */
        act = flock_values[act - 1] | (operation & PHP_LOCK_NB ? LOCK_NB : 0);
        if (php_stream_lock(stream, act)) {
-#ifdef PHP_WIN32
-               if (operation && errno == ERROR_INVALID_BLOCK && arg3 && PZVAL_IS_REF(arg3)) {
-#else
                if (operation && errno == EWOULDBLOCK && arg3 && PZVAL_IS_REF(arg3)) {
-#endif
                        Z_LVAL_P(arg3) = 1;
                }
                RETURN_FALSE;
index 973ce539056ed8233a3ab3601892dfef8b8c0ea8..3eb4e92d8ff9de3aeb524a92081f250770726384 100644 (file)
@@ -125,8 +125,12 @@ PHPAPI int php_flock(int fd, int operation)
     DWORD low = 1, high = 0;
     OVERLAPPED offset =
     {0, 0, 0, 0, NULL};
-    if (hdl < 0)
+       DWORD err;
+
+    if (hdl < 0) {
+               _set_errno(EBADF);
         return -1;              /* error in file descriptor */
+       }
     /* bug for bug compatible with Unix */
     UnlockFileEx(hdl, 0, low, high, &offset);
     switch (operation & ~LOCK_NB) {    /* translate to LockFileEx() op */
@@ -146,12 +150,14 @@ PHPAPI int php_flock(int fd, int operation)
         default:                /* default */
             break;
     }
-       /* Under Win32 MT library, errno is not a variable but a function call,
-        * which cannot be assigned to.
-        */
-#if !defined(PHP_WIN32)
-    errno = EINVAL;             /* bad call */
-#endif
+
+       err = GetLastError();
+       if (ERROR_LOCK_VIOLATION == err || ERROR_SHARING_VIOLATION == err) {
+               _set_errno(EWOULDBLOCK);
+       } else {
+               _set_errno(EINVAL);             /* bad call */
+       }
+
     return -1;
 }
 /* }}} */