1 #include <stdio.h> 2 #include <sys/stat.h> 3 #include <errno.h> 4 #include <sys/types.h> 5 #include <fcntl.h> 6 #include <unistd.h> 7 8 int lock_reg(int, int, off_t, int, off_t, int); 9 10 #define read_lock(fd, offset, whence, len) \ 11 lock_reg(fd, F_RDLCK, offset, whence, len, F_SETLK) 12 #define write_lock(fd, offset, whence, len) \ 13 lock_reg(fd, F_WRLCK, offset, whence, len, F_SETLK) 14 #define un_lock(fd, offset, whence, len) \ 15 lock_reg(fd, F_UNLCK, offset, whence, len, F_SETLK) 16 #define readb_lock(fd, offset, whence, len) \ 17 lock_reg(fd, F_RDLCK, offset, whence, len, F_SETLKW) 18 #define writeb_lock(fd, offset, whence, len) \ 19 lock_reg(fd, F_WRLCK, offset, whence, len, F_SETLKW) 20 #define unb_lock(fd, offset, whence, len) \ 21 lock_reg(fd, F_UNLCK, offset, whence, len, F_SETLKW) 22