1 /* 2 ** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for 3 ** distribution information. 4 */ 5 6 #if HAVE_CONFIG_H 7 #include "config.h" 8 #endif 9 #include <sys/types.h> 10 #if HAVE_FCNTL_H 11 #include <fcntl.h> 12 #endif 13 #if HAVE_SYS_FCNTL_H 14 #include <sys/fcntl.h> 15 #endif 16 #include "liblock.h" 17 ll_lockfd(int fd,int ltype,LL_OFFSET_TYPE start,LL_OFFSET_TYPE len)18int ll_lockfd(int fd, int ltype, LL_OFFSET_TYPE start, LL_OFFSET_TYPE len) 19 { 20 #if HAS_FLOCK_T 21 flock_t ft; 22 #else 23 struct flock ft; 24 #endif 25 26 ft.l_type=ltype & ll_unlock ? F_UNLCK: 27 ltype & ll_writelock ? F_WRLCK:F_RDLCK; 28 ft.l_whence=ltype & ll_whence_curpos ? 1: 29 ltype & ll_whence_end ? 2:0; 30 ft.l_start=start; 31 ft.l_len=len; 32 33 return (fcntl(fd, (ltype & ll_unlock) == 0 && (ltype & ll_wait) 34 ? F_SETLKW:F_SETLK, &ft)); 35 } 36