summaryrefslogtreecommitdiffstats
path: root/lib/libutil/flopen.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2007-08-03 06:32:45 +0000
committerdes <des@FreeBSD.org>2007-08-03 06:32:45 +0000
commit3cfbe77a3e1ea4ec1530405c1d7a6192a03a46af (patch)
tree9ddf37f6148623c37036890aac9e8d3388a697ce /lib/libutil/flopen.c
parent8f39689f22ef1c7ad458c19e91b75513946a3ac7 (diff)
downloadFreeBSD-src-3cfbe77a3e1ea4ec1530405c1d7a6192a03a46af.zip
FreeBSD-src-3cfbe77a3e1ea4ec1530405c1d7a6192a03a46af.tar.gz
Use fcntl(2)-style locks instead of less-portable flock(2)-style locks.
Approved by: re (kensmith)
Diffstat (limited to 'lib/libutil/flopen.c')
-rw-r--r--lib/libutil/flopen.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/libutil/flopen.c b/lib/libutil/flopen.c
index 23742f7..f285ac5 100644
--- a/lib/libutil/flopen.c
+++ b/lib/libutil/flopen.c
@@ -43,6 +43,7 @@ flopen(const char *path, int flags, ...)
{
int fd, operation, serrno, trunc;
struct stat sb, fsb;
+ struct flock lock;
mode_t mode;
#ifdef O_EXLOCK
@@ -58,9 +59,11 @@ flopen(const char *path, int flags, ...)
va_end(ap);
}
- operation = LOCK_EX;
- if (flags & O_NONBLOCK)
- operation |= LOCK_NB;
+ lock.l_type = (flags & O_RDONLY) ? F_RDLCK : F_WRLCK;
+ lock.l_start = 0;
+ lock.l_whence = SEEK_SET;
+ lock.l_len = 0;
+ operation = (flags & O_NONBLOCK) ? F_SETLK : F_SETLKW;
trunc = (flags & O_TRUNC);
flags &= ~O_TRUNC;
@@ -69,7 +72,7 @@ flopen(const char *path, int flags, ...)
if ((fd = open(path, flags, mode)) == -1)
/* non-existent or no access */
return (-1);
- if (flock(fd, operation) == -1) {
+ if (fcntl(fd, operation, &lock) == -1) {
/* unsupported or interrupted */
serrno = errno;
close(fd);
OpenPOWER on IntegriCloud