diff options
Diffstat (limited to 'src/libstddjb/fd_islocked.c')
-rw-r--r-- | src/libstddjb/fd_islocked.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libstddjb/fd_islocked.c b/src/libstddjb/fd_islocked.c new file mode 100644 index 0000000..bf9f9e8 --- /dev/null +++ b/src/libstddjb/fd_islocked.c @@ -0,0 +1,17 @@ +/* ISC license. */ + +#include <fcntl.h> + +#include <skalibs/djbunix.h> + +int fd_islocked (int fd) +{ + struct flock fl = + { + .l_type = F_RDLCK, + .l_whence = SEEK_SET, + .l_start = 0, + .l_len = 0 + } ; + return fcntl(fd, F_GETLK, &fl) < 0 ? -1 : fl.l_type != F_UNLCK ; +} |