diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2020-11-29 21:02:32 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2020-11-29 21:02:32 +0000 |
commit | 90b819c6d832046840018ff08b9bc5d0e3b69c37 (patch) | |
tree | efea05788cc982395ee114474d84096e7fc70862 /src/libstddjb/fd_unlock.c | |
parent | e6c5c984461dc4cec0ef2d68524d6bd457e23853 (diff) | |
download | skalibs-90b819c6d832046840018ff08b9bc5d0e3b69c37.tar.xz |
Revamp lock primitives; prepare for 2.10.0.0 instead of 2.9.4.0
flock() doesn't have a way to test for a lock without taking it.
lockf() doesn't have shared locks.
The only way to have both is fcntl(). So I rewrote all the
locking stuff around fcntl(), and used the opportunity to change
the interface.
The point of changing the interface is to stop having to bother
with the old one, so to hell with compatibility, let's just do a
major bump.
Diffstat (limited to 'src/libstddjb/fd_unlock.c')
-rw-r--r-- | src/libstddjb/fd_unlock.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libstddjb/fd_unlock.c b/src/libstddjb/fd_unlock.c new file mode 100644 index 0000000..4c63fd9 --- /dev/null +++ b/src/libstddjb/fd_unlock.c @@ -0,0 +1,20 @@ +/* ISC license. */ + +#include <fcntl.h> +#include <errno.h> + +#include <skalibs/djbunix.h> + +void fd_unlock (int fd) +{ + struct flock fl = + { + .l_type = F_UNLCK, + .l_whence = SEEK_SET, + .l_start = 0, + .l_len = 0 + } ; + int e = errno ; + fcntl(fd, F_SETLK, &fl) ; + errno = e ; +} |