/* 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;
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 */
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;
}
/* }}} */