1 #include <sys/types.h>
2 #include <unistd.h>
3 #include <fcntl.h>
4 #include "uolock.h"
5 
6 static int
lock_region(int fd,int cmd,int typ,off_t start,int whence,off_t len)7 lock_region (int fd, int cmd, int typ, off_t start, int whence, off_t len)
8 {
9 	struct flock lock;
10 	lock.l_type = typ;
11 	lock.l_start = start;
12 	lock.l_len = len;
13 	lock.l_whence = whence;
14 	return fcntl (fd, cmd, &lock);
15 }
16 
uolock_share(int fd)17 int uolock_share(int fd)
18 { return lock_region(fd,F_SETLKW, F_RDLCK, 0, SEEK_SET, 0); }
uolock_tryshare(int fd)19 int uolock_tryshare(int fd)
20 { return lock_region(fd,F_SETLK, F_RDLCK, 0, SEEK_SET, 0); }
uolock_excl(int fd)21 int uolock_excl(int fd)
22 { return lock_region(fd,F_SETLKW, F_WRLCK, 0, SEEK_SET, 0); }
uolock_tryexcl(int fd)23 int uolock_tryexcl(int fd)
24 { return lock_region(fd,F_SETLK, F_WRLCK, 0, SEEK_SET, 0); }
uolock_unlock(int fd)25 int uolock_unlock(int fd)
26 { return lock_region(fd,F_SETLK, F_UNLCK, 0, SEEK_SET, 0); }
27 
28 
29