diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2009-09-17 16:16:44 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2009-09-17 16:16:44 +0000 |
commit | 0c64a86be7a0a1b3a4d107a32f8ebcc64ffcb474 (patch) | |
tree | ca021f821714790d7e02bc52db869c4696403fe7 /libutil | |
parent | b19ea5389a00f568fc1415186a0d7626acb19571 (diff) | |
parent | 1a8db5b2127d43a49d986fb97b62bd51db655b10 (diff) | |
download | pw-darwin-0c64a86be7a0a1b3a4d107a32f8ebcc64ffcb474.tar.gz pw-darwin-0c64a86be7a0a1b3a4d107a32f8ebcc64ffcb474.tar.zst pw-darwin-0c64a86be7a0a1b3a4d107a32f8ebcc64ffcb474.zip |
Merge from head
Diffstat (limited to 'libutil')
-rw-r--r-- | libutil/flopen.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/libutil/flopen.c b/libutil/flopen.c index ae98daf..754c9c0 100644 --- a/libutil/flopen.c +++ b/libutil/flopen.c @@ -28,12 +28,11 @@ #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,7 +41,6 @@ int flopen(const char *path, int flags, ...) { int fd, operation, serrno, trunc; - struct flock lock; struct stat sb, fsb; mode_t mode; @@ -59,10 +57,9 @@ flopen(const char *path, int flags, ...) va_end(ap); } - memset(&lock, 0, sizeof lock); - lock.l_type = ((flags & O_ACCMODE) == O_RDONLY) ? F_RDLCK : F_WRLCK; - lock.l_whence = SEEK_SET; - operation = (flags & O_NONBLOCK) ? F_SETLK : F_SETLKW; + operation = LOCK_EX; + if (flags & O_NONBLOCK) + operation |= LOCK_NB; trunc = (flags & O_TRUNC); flags &= ~O_TRUNC; @@ -71,7 +68,7 @@ flopen(const char *path, int flags, ...) if ((fd = open(path, flags, mode)) == -1) /* non-existent or no access */ return (-1); - if (fcntl(fd, operation, &lock) == -1) { + if (flock(fd, operation) == -1) { /* unsupported or interrupted */ serrno = errno; (void)close(fd); |