From: Anatol Belski Date: Sat, 21 Feb 2015 13:10:59 +0000 (+0100) Subject: revisit fix for bug #65272 X-Git-Tag: php-5.5.23RC1~32 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6751f8b314e60193534f7d8c1c1d32660a27efc8;p=php revisit fix for bug #65272 --- diff --git a/ext/standard/file.c b/ext/standard/file.c index c15dd50507..c2e71d1dea 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 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; } /* }}} */