Back to index

courier  0.68.2
lockfcntl.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 #include      "liblock.h"
00017 
00018 int    ll_lockfd(int fd, int ltype, LL_OFFSET_TYPE start, LL_OFFSET_TYPE len)
00019 {
00020 #if HAS_FLOCK_T
00021 flock_t       ft;
00022 #else
00023 struct flock ft;
00024 #endif
00025 
00026        ft.l_type=ltype & ll_unlock ? F_UNLCK:
00027               ltype & ll_writelock ? F_WRLCK:F_RDLCK;
00028        ft.l_whence=ltype & ll_whence_curpos ? 1:
00029                      ltype & ll_whence_end ? 2:0;
00030        ft.l_start=start;
00031        ft.l_len=len;
00032 
00033        return (fcntl(fd, (ltype & ll_unlock) == 0 && (ltype & ll_wait)
00034                      ? F_SETLKW:F_SETLK, &ft));
00035 }