Imported Upstream version 0.66.1
[hcoop/debian/courier-authlib.git] / libs / liblock / lockflock.c
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 #if HAVE_SYS_FILE_H
17 #include <sys/file.h>
18 #endif
19 #include <errno.h>
20 #include "liblock.h"
21
22 int ll_lockfd(int fd, int ltype, LL_OFFSET_TYPE start, LL_OFFSET_TYPE len)
23 {
24 if (start || len
25 || (ltype & ll_whence_curpos)
26 || (ltype & ll_whence_end))
27 {
28 errno=EINVAL;
29 return (-1);
30 }
31
32 return (flock(fd, ltype & ll_unlock ? LOCK_UN:
33 (ltype & ll_writelock ? LOCK_EX:LOCK_SH) |
34 (ltype & ll_wait ? 0:LOCK_NB)));
35 }