summaryrefslogtreecommitdiff
path: root/win32/win32.c
diff options
context:
space:
mode:
Diffstat (limited to 'win32/win32.c')
-rw-r--r--win32/win32.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/win32/win32.c b/win32/win32.c
index ef6886af2b..ce69f3b826 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -250,7 +250,20 @@ GetCurrentThreadHandle(void)
/* simulate flock by locking a range on the file */
-#define LK_ERR(f,i) ((f) ? (i = 0) : (errno = GetLastError() == ERROR_LOCK_VIOLATION ? EWOULDBLOCK : EACCES))
+#define LK_ERR(f,i) \
+ do { \
+ if (f) \
+ i = 0; \
+ else { \
+ DWORD err = GetLastError(); \
+ if (err == ERROR_LOCK_VIOLATION) \
+ errno = EWOULDBLOCK; \
+ else if (err == ERROR_NOT_LOCKED) \
+ i = 0; \
+ else \
+ errno = map_errno(err); \
+ } \
+ } while (0)
#define LK_LEN ULONG_MAX
static VALUE