summaryrefslogtreecommitdiff
path: root/src/libstddjb/fd_islocked.c
blob: 8d5ef78417ef565a4da243413637fd54ab6d9359 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* ISC license. */

#include <fcntl.h>
#include <unistd.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 ;
}