diff --git a/src/sbbs3/smbwrap.c b/src/sbbs3/smbwrap.c index 2c07771913cac5528be52ceab65e473f68543433..a1fdd15247704e40f19297d8cb2b1a96e3d61487 100644 --- a/src/sbbs3/smbwrap.c +++ b/src/sbbs3/smbwrap.c @@ -179,9 +179,16 @@ long SMBCALL filelength(int fd) /* Sets a lock on a portion of a file */ int SMBCALL lock(int fd, long pos, int len) { + int flags; struct flock alock; - alock.l_type = F_WRLCK; // set a write lock to prevent all access + if((flags=fcntl(fd,F_GETFL))<0) + return -1; + + if(flags==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 = len;