Skip to content

Commit 6751f8b

Browse files
committed
revisit fix for bug #65272
1 parent 3082177 commit 6751f8b

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

ext/standard/file.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,7 @@ PHP_FUNCTION(flock)
356356
/* flock_values contains all possible actions if (operation & 4) we won't block on the lock */
357357
act = flock_values[act - 1] | (operation & PHP_LOCK_NB ? LOCK_NB : 0);
358358
if (php_stream_lock(stream, act)) {
359-
#ifdef PHP_WIN32
360-
if (operation && errno == ERROR_INVALID_BLOCK && arg3 && PZVAL_IS_REF(arg3)) {
361-
#else
362359
if (operation && errno == EWOULDBLOCK && arg3 && PZVAL_IS_REF(arg3)) {
363-
#endif
364360
Z_LVAL_P(arg3) = 1;
365361
}
366362
RETURN_FALSE;

ext/standard/flock_compat.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,12 @@ PHPAPI int php_flock(int fd, int operation)
125125
DWORD low = 1, high = 0;
126126
OVERLAPPED offset =
127127
{0, 0, 0, 0, NULL};
128-
if (hdl < 0)
128+
DWORD err;
129+
130+
if (hdl < 0) {
131+
_set_errno(EBADF);
129132
return -1; /* error in file descriptor */
133+
}
130134
/* bug for bug compatible with Unix */
131135
UnlockFileEx(hdl, 0, low, high, &offset);
132136
switch (operation & ~LOCK_NB) { /* translate to LockFileEx() op */
@@ -146,12 +150,14 @@ PHPAPI int php_flock(int fd, int operation)
146150
default: /* default */
147151
break;
148152
}
149-
/* Under Win32 MT library, errno is not a variable but a function call,
150-
* which cannot be assigned to.
151-
*/
152-
#if !defined(PHP_WIN32)
153-
errno = EINVAL; /* bad call */
154-
#endif
153+
154+
err = GetLastError();
155+
if (ERROR_LOCK_VIOLATION == err || ERROR_SHARING_VIOLATION == err) {
156+
_set_errno(EWOULDBLOCK);
157+
} else {
158+
_set_errno(EINVAL); /* bad call */
159+
}
160+
155161
return -1;
156162
}
157163
/* }}} */

0 commit comments

Comments
 (0)