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

Remove the F_SANE*LCKNO stuff

It appears Deuce's FreeBSD patch isn't going to be accepted/merged
(https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=50827), so I'm
making this code a little more readable/manageable by removing this
unused feature... for now, with Deuce's approval.
parent 3c0a335d
No related branches found
No related tags found
No related merge requests found
Pipeline #7111 passed
......@@ -78,38 +78,34 @@ off_t filelength(int fd)
/* Sets a lock on a portion of a file */
int lock(int fd, off_t pos, off_t len)
{
#if defined(F_SANERDLCKNO) || !defined(BSD)
#if !defined(BSD)
struct flock alock = {0};
int cmd = F_SETLK;
#ifdef F_OFD_SETLK
cmd = F_OFD_SETLK;
#endif
#ifndef F_SANEWRLCKNO
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 */
#else
alock.l_type = F_SANEWRLCKNO;
#endif
alock.l_whence = L_SET; /* SEEK_SET */
alock.l_start = pos;
alock.l_len = (int)len;
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;
int result = fcntl(fd, cmd, &alock);
if(result == -1 && errno != EINVAL)
return -1;
#ifdef F_OFD_SETLK
if(result == 0)
return 0;
#endif
#endif
int result = fcntl(fd, cmd, &alock);
if(result == -1 && errno != EINVAL)
return -1;
#ifdef F_OFD_SETLK
if(result == 0)
return 0;
#endif
#endif
#if !defined(F_SANEWRLCKNO) && !defined(__QNX__) && !defined(__solaris__)
#if !defined(__QNX__) && !defined(__solaris__)
/* use flock (doesn't work over NFS) */
if(flock(fd,LOCK_EX|LOCK_NB)!=0 && errno != EOPNOTSUPP)
return(-1);
......@@ -122,17 +118,13 @@ int lock(int fd, off_t pos, off_t len)
int unlock(int fd, off_t pos, off_t len)
{
#if defined(F_SANEUNLCK) || !defined(BSD)
#if !defined(BSD)
struct flock alock = {0};
int cmd = F_SETLK;
#ifdef F_OFD_SETLK
cmd = F_OFD_SETLK;
#endif
#ifdef F_SANEUNLCK
alock.l_type = F_SANEUNLCK; /* remove the lock */
#else
alock.l_type = F_UNLCK; /* remove the lock */
#endif
alock.l_whence = L_SET;
alock.l_start = pos;
alock.l_len = (int)len;
......@@ -145,7 +137,7 @@ int unlock(int fd, off_t pos, off_t len)
#endif
#endif
#if !defined(F_SANEUNLCK) && !defined(__QNX__) && !defined(__solaris__)
#if !defined(__QNX__) && !defined(__solaris__)
/* use flock (doesn't work over NFS) */
if(flock(fd,LOCK_UN|LOCK_NB)!=0 && errno != EOPNOTSUPP)
return(-1);
......@@ -199,10 +191,8 @@ int sopen(const char *fn, int sh_access, int share, ...)
#else
int pmode=0;
#endif
#ifndef F_SANEWRLCKNO
int flock_op=LOCK_NB; /* non-blocking */
#endif
#if defined(F_SANEWRLCKNO) || !defined(BSD)
#if !defined(BSD)
struct flock alock = {0};
#endif
va_list ap;
......@@ -218,7 +208,8 @@ int sopen(const char *fn, int sh_access, int share, ...)
if (share == SH_DENYNO || share == SH_COMPAT) /* no lock needed */
return fd;
#if defined(F_SANEWRLCKNO) || !defined(BSD)
#if !defined(BSD)
int cmd = F_SETLK;
#ifdef F_OFD_SETLK
cmd = F_OFD_SETLK;
......@@ -235,7 +226,7 @@ int sopen(const char *fn, int sh_access, int share, ...)
}
#endif
#if !defined(F_SANEWRLCKNO) && !defined(__QNX__) && !defined(__solaris__)
#if !defined(__QNX__) && !defined(__solaris__)
/* use flock (doesn't work over NFS) */
if(share==SH_DENYRW)
flock_op|=LOCK_EX;
......
......@@ -102,17 +102,8 @@
#define O_DENYNONE (1U<<31) /* req'd for Baja/nopen compatibility */
#define SH_DENYNO 2 /* no locks */
#ifdef F_SANEWRLCKNO
#define SH_DENYRW F_SANEWRLCKNO /* exclusive lock */
#else
#define SH_DENYRW F_WRLCK /* exclusive lock */
#endif
#ifdef F_SANERDLCKNO
#define SH_DENYWR F_SANERDLCKNO /* shareable lock */
#else
#define SH_DENYWR F_RDLCK /* shareable lock */
#endif
#define SH_DENYRW F_WRLCK /* exclusive lock */
#define SH_DENYWR F_RDLCK /* shareable lock */
#ifndef SH_COMPAT
#define SH_COMPAT 0
......
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