1 #include <stdlib.h>
2 #include <unistd.h>
3
4 #include "nfs_flock.h"
5
lock_reg(int fd,int type,off_t offset,int whence,off_t len,int cmd)6 int lock_reg(int fd, int type, off_t offset, int whence, off_t len, int cmd)
7 {
8 struct flock lock;
9
10 lock.l_type = type;
11 lock.l_start = offset;
12 lock.l_whence = whence;
13 lock.l_len = len;
14
15 return (fcntl(fd, cmd, &lock));
16 }
17
lock_test(int fd,int type,off_t offset,int whence,int len)18 int lock_test(int fd, int type, off_t offset, int whence, int len)
19 {
20 struct flock lock;
21
22 lock.l_type = type;
23 lock.l_start = offset;
24 lock.l_whence = whence;
25 lock.l_len = len;
26
27 if (fcntl(fd, F_GETLK, &lock) < 0) {
28 perror("F_GETLK");
29 exit(2);
30 }
31
32 if (lock.l_type == F_UNLCK)
33 return (0);
34
35 return (lock.l_pid);
36 }
37