Back to index

courier  0.68.2
lockflock.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for
00003 ** distribution information.
00004 */
00005 
00006 #if    HAVE_CONFIG_H
00007 #include      "config.h"
00008 #endif
00009 #include      <sys/types.h>
00010 #if    HAVE_FCNTL_H
00011 #include      <fcntl.h>
00012 #endif
00013 #if    HAVE_SYS_FCNTL_H
00014 #include      <sys/fcntl.h>
00015 #endif
00016 #if    HAVE_SYS_FILE_H
00017 #include      <sys/file.h>
00018 #endif
00019 #include      <errno.h>
00020 #include      "liblock.h"
00021 
00022 int    ll_lockfd(int fd, int ltype, LL_OFFSET_TYPE start, LL_OFFSET_TYPE len)
00023 {
00024        if (start || len
00025               || (ltype & ll_whence_curpos)
00026               || (ltype & ll_whence_end))
00027        {
00028               errno=EINVAL;
00029               return (-1);
00030        }
00031 
00032        return (flock(fd, ltype & ll_unlock ? LOCK_UN:
00033               (ltype & ll_writelock ? LOCK_EX:LOCK_SH) |
00034               (ltype & ll_wait ? 0:LOCK_NB)));
00035 }