From 3534b428629be185e096be99e3bd5fdfe32d5544 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 18 Sep 2014 18:55:44 +0000 Subject: initial commit with rc for skalibs-2.0.0.0 --- src/libstddjb/lock_exnb.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/libstddjb/lock_exnb.c (limited to 'src/libstddjb/lock_exnb.c') diff --git a/src/libstddjb/lock_exnb.c b/src/libstddjb/lock_exnb.c new file mode 100644 index 0000000..7fed9f0 --- /dev/null +++ b/src/libstddjb/lock_exnb.c @@ -0,0 +1,38 @@ +/* ISC license. */ + +#include + +#ifdef SKALIBS_HASFLOCK + +#include +#include +#include +#include + +int lock_exnb (int fd) +{ + register int r ; + do + r = flock(fd, LOCK_EX | LOCK_NB) ; + while ((r == -1) && (errno == EINTR)) ; + return r ; +} + +#else + +#include +#include +#include +#include + +int lock_exnb (int fd) +{ + register int r ; + do + r = lockf(fd, F_TLOCK, 0) ; + while ((r == -1) && (errno == EINTR)) ; + if ((r == -1) && (errno == EACCES)) errno = EAGAIN ; + return r ; +} + +#endif -- cgit v1.2.3