| 1 | /* |
| 2 | ** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for |
| 3 | ** distribution information. |
| 4 | */ |
| 5 | |
| 6 | /* $Id: lockflock.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 | #if HAVE_SYS_FILE_H |
| 18 | #include <sys/file.h> |
| 19 | #endif |
| 20 | #include <errno.h> |
| 21 | #include "liblock.h" |
| 22 | |
| 23 | int ll_lockfd(int fd, int ltype, LL_OFFSET_TYPE start, LL_OFFSET_TYPE len) |
| 24 | { |
| 25 | if (start || len |
| 26 | || (ltype & ll_whence_curpos) |
| 27 | || (ltype & ll_whence_end)) |
| 28 | { |
| 29 | errno=EINVAL; |
| 30 | return (-1); |
| 31 | } |
| 32 | |
| 33 | return (flock(fd, ltype & ll_unlock ? LOCK_UN: |
| 34 | (ltype & ll_writelock ? LOCK_EX:LOCK_SH) | |
| 35 | (ltype & ll_wait ? 0:LOCK_NB))); |
| 36 | } |