1 /* $Id: lockfile.c 6020 2002-12-20 00:19:58Z rra $
3 ** Lock a file or a range in a file.
5 ** Provides inn_lock_file and inn_lock_range functions to lock or unlock a
6 ** file or ranges within a file with a more convenient syntax than fcntl.
7 ** Assume that fcntl is available.
18 inn_lock_file(int fd, enum inn_locktype type, bool block)
20 return inn_lock_range(fd, type, block, 0, 0);
24 inn_lock_range(int fd, enum inn_locktype type, bool block, off_t offset,
31 case INN_LOCK_READ: fl.l_type = F_RDLCK; break;
32 case INN_LOCK_WRITE: fl.l_type = F_WRLCK; break;
34 case INN_LOCK_UNLOCK: fl.l_type = F_UNLCK; break;
38 fl.l_whence = SEEK_SET;
42 status = fcntl(fd, block ? F_SETLKW : F_SETLK, &fl);
43 } while (status == -1 && errno == EINTR);
44 return (status != -1);