From 11b73134563ce26a6c954f08fbd26bdbecce3ca0 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Tue, 7 Nov 2000 11:38:52 +0000
Subject: [PATCH] lock() for Unix now sets the appropriate lock type (shareable
 or exclusive) based on how the file was initially opened.

---
 src/sbbs3/smbwrap.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/sbbs3/smbwrap.c b/src/sbbs3/smbwrap.c
index 2c07771913..a1fdd15247 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;
-- 
GitLab