fd_islocked.c (308B)
1 /* ISC license. */ 2 3 #include <unistd.h> 4 5 #include <skalibs/fcntl.h> 6 #include <skalibs/djbunix.h> 7 8 int fd_islocked (int fd) 9 { 10 struct flock fl = 11 { 12 .l_type = F_RDLCK, 13 .l_whence = SEEK_SET, 14 .l_start = 0, 15 .l_len = 0 16 } ; 17 return fcntl(fd, F_GETLK, &fl) == -1 ? -1 : fl.l_type != F_UNLCK ; 18 }