summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 e0333df09e..85f35d1323 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -364,11 +364,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 && wouldblock && PZVAL_IS_REF(wouldblock)) {
-#else
if (operation && errno == EWOULDBLOCK && wouldblock && PZVAL_IS_REF(wouldblock)) {
-#endif
Z_LVAL_P(wouldblock) = 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;
}
/* }}} */