summaryrefslogtreecommitdiffstats
path: root/libutil
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2008-10-20 18:02:16 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2008-10-20 18:02:16 +0000
commit86961ef741cc24178ecb54f42e4ba78eaff708d6 (patch)
tree71851a75a1734708fda89d7c61dca8926fab2331 /libutil
parentdb67f9a9560f36480659cb6e74f1314a4881e09b (diff)
downloadpw-darwin-86961ef741cc24178ecb54f42e4ba78eaff708d6.tar.gz
pw-darwin-86961ef741cc24178ecb54f42e4ba78eaff708d6.tar.zst
pw-darwin-86961ef741cc24178ecb54f42e4ba78eaff708d6.zip
Reimplement flopen(3) using fcntl(2) locks instead of flock(2) locks.
Diffstat (limited to 'libutil')
-rw-r--r--libutil/flopen.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/libutil/flopen.c b/libutil/flopen.c
index 23742f7..a5bf8c6 100644
--- a/libutil/flopen.c
+++ b/libutil/flopen.c
@@ -28,12 +28,12 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <sys/file.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
+#include <string.h>
#include <unistd.h>
#include <libutil.h>
@@ -42,6 +42,7 @@ int
flopen(const char *path, int flags, ...)
{
int fd, operation, serrno, trunc;
+ struct flock flock;
struct stat sb, fsb;
mode_t mode;
@@ -58,9 +59,10 @@ flopen(const char *path, int flags, ...)
va_end(ap);
}
- operation = LOCK_EX;
- if (flags & O_NONBLOCK)
- operation |= LOCK_NB;
+ memset(&flock, 0, sizeof flock);
+ flock.l_type = F_WRLCK;
+ flock.l_whence = SEEK_SET;
+ operation = (flags & O_NONBLOCK) ? F_SETLK : F_SETLKW;
trunc = (flags & O_TRUNC);
flags &= ~O_TRUNC;
@@ -69,7 +71,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, &flock) == -1) {
/* unsupported or interrupted */
serrno = errno;
close(fd);