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