2 * $Id: lock.c,v 1.2 2002/02/27 15:51:20 dfs Exp $
4 * Copyright (C) 1997 Lars Fenneberg
6 * See the file COPYRIGHT for the respective terms and conditions.
7 * If the file is missing contact me at lf@elemental.net
8 * and I'll send you a copy.
15 #if defined(HAVE_FLOCK)
17 int do_lock_exclusive(int fd)
19 return flock(fd, LOCK_EX|LOCK_NB);
24 return flock(fd, LOCK_UN);
27 #elif defined(HAVE_FCNTL)
29 int do_lock_exclusive(int fd)
34 memset((void *)&fl, 0, sizeof(fl));
37 fl.l_whence = fl.l_start = 0;
38 fl.l_len = 0; /* 0 means "to end of file" */
40 res = fcntl(fd, F_SETLK, &fl);
42 if ((res == -1) && (errno == EAGAIN))
52 memset((void *)&fl, 0, sizeof(fl));
55 fl.l_whence = fl.l_start = 0;
56 fl.l_len = 0; /* 0 means "to end of file" */
58 return fcntl(fd, F_SETLK, &fl);
62 YOU_LOOSE "need either flock(2) or fcntl(2)"