Thanks! > +static BOOL > +do_lock_shared (HANDLE h, int non_blocking)
> +static BOOL > +do_lock_exclusive (HANDLE h, int non_blocking) There's quite some duplication here. However, with the other changes below it might become acceptable. > + case ERROR_LOCK_VIOLATION: > + /* EWOULDBLOCK is not available on MinGW. */ If you use the errno module, EWOULDBLOCK is added. However, it is better to make it a synonym of EAGAIN as it is on POSIX platforms. > + /* Start offset is 0. */ > + memset (&ovlp, 0, sizeof ovlp); > + ovlp.Offset = 0; > + ovlp.OffsetHigh = 0; > + ovlp.hEvent = 0; No need to set fields to zero. > + memset (&fl, 0, sizeof fl); > + fl.l_whence = SEEK_SET; > + fl.l_start = 0; > + fl.l_len = 0; /* Special case -- means whole file. */ Likewise (even SEEK_SET is zero). > + return fcntl (fd, cmd, &fl); You need to change EACCES to EWOULDBLOCK here if fcntl F_SETLK fails. Thanks! Paolo