15 /* a byte range locking function - return 0 on success
16 this functions locks/unlocks 1 byte at the specified offset */
17 static int tdb_brlock(int fd, off_t offset, int set, int rw_type, int lck_type)
21 fl.l_type = set==LOCK_SET?rw_type:F_UNLCK;
22 fl.l_whence = SEEK_SET;
27 if (fcntl(fd, lck_type, &fl) != 0) {
36 int fd = open("lcktest.dat", O_RDWR|O_CREAT|O_TRUNC, 0600);
38 tdb_brlock(fd, 0, LOCK_SET, F_RDLCK, F_SETLKW);
44 fd = open("lcktest.dat", O_RDWR, 0600);
46 if (tdb_brlock(fd, 0, LOCK_SET, F_WRLCK, F_SETLKW) == 0) {
47 printf("child doesn't hold lock\n");
49 printf("child does hold lock\n");