summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2015-02-21 14:10:59 +0100
committerAnatol Belski <ab@php.net>2015-02-21 14:10:59 +0100
commit6751f8b314e60193534f7d8c1c1d32660a27efc8 (patch)
tree1831ecbca4c0688c1a75b553daebd5591da929e0
parent3082177beebdf148b5b4165f5efbc2c26fd0c01b (diff)
downloadphp-git-6751f8b314e60193534f7d8c1c1d32660a27efc8.tar.gz
revisit fix for bug #65272
-rw-r--r--ext/standard/file.c4
-rw-r--r--ext/standard/flock_compat.c20
2 files changed, 13 insertions, 11 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c
index c15dd50507..c2e71d1dea 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -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;
diff --git a/ext/standard/flock_compat.c b/ext/standard/flock_compat.c
index 973ce53905..3eb4e92d8f 100644
--- a/ext/standard/flock_compat.c
+++ b/ext/standard/flock_compat.c
@@ -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;
}
/* }}} */