Skip to content

Commit 3cf2b7c

Browse files
committed
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5: revisit fix for bug #65272 Conflicts: ext/standard/file.c
2 parents b21d084 + 6751f8b commit 3cf2b7c

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
@@ -364,11 +364,7 @@ PHP_FUNCTION(flock)
364364
/* flock_values contains all possible actions if (operation & 4) we won't block on the lock */
365365
act = flock_values[act - 1] | (operation & PHP_LOCK_NB ? LOCK_NB : 0);
366366
if (php_stream_lock(stream, act)) {
367-
#ifdef PHP_WIN32
368-
if (operation && errno == ERROR_INVALID_BLOCK && wouldblock && PZVAL_IS_REF(wouldblock)) {
369-
#else
370367
if (operation && errno == EWOULDBLOCK && wouldblock && PZVAL_IS_REF(wouldblock)) {
371-
#endif
372368
Z_LVAL_P(wouldblock) = 1;
373369
}
374370
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)