com php-src: revisit fix for bug #65272: ext/standard/file.c ext/standard/flock_compat.c
| From: | Anatol Belski | Date: | Sat, 21 Feb 2015 13:10:59 +0000 |
| Subject: | com php-src: revisit fix for bug #65272: ext/standard/file.c ext/standard/flock_compat.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-85041@lists.php.net to get a copy of this message | ||
Commit: 6751f8b314e60193534f7d8c1c1d32660a27efc8
Author: Anatol Belski <ab@php.net> Sat, 21 Feb 2015 14:10:59 +0100
Parents: 3082177beebdf148b5b4165f5efbc2c26fd0c01b
Branches: PHP-5.5 PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=6751f8b314e60193534f7d8c1c1d32660a27efc8
Log:
revisit fix for bug #65272
Bugs:
https://bugs.php.net/65272
Changed paths:
M ext/standard/file.c
M ext/standard/flock_compat.c
Diff:
diff --git a/ext/standard/file.c b/ext/standard/file.c
index c15dd50..c2e71d1 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 973ce53..3eb4e92 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;
}
/* }}} */