Skip to content
Snippets Groups Projects
Commit d9d86d6a authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Revert the lock() change in commit 043feff8

So this change is needed or else fcntl() will fail with errno=BADF if trying
to write-lock a file that was opened read-only. Oh well. Added a comment
explaining the rationale.
parent ec1c6bd3
No related branches found
No related tags found
No related merge requests found
......@@ -89,7 +89,14 @@ int lock(int fd, off_t pos, off_t len)
cmd = F_OFD_SETLK;
#endif
alock.l_type = F_WRLCK; /* set write lock to prevent all access */
// fcntl() will return EBADF if we try to set a write lock a file opened O_RDONLY
int flags;
if((flags=fcntl(fd,F_GETFL))==-1)
return -1;
if((flags & (O_RDONLY|O_RDWR|O_WRONLY))==O_RDONLY)
alock.l_type = F_RDLCK; /* set read lock to prevent writes */
else
alock.l_type = F_WRLCK; /* set write lock to prevent all access */
alock.l_whence = L_SET; /* SEEK_SET */
alock.l_start = pos;
alock.l_len = (int)len;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment