• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * $Id: lock.c,v 1.1 2004/11/14 07:26:26 paulus Exp $
3  *
4  * Copyright (C) 1997 Lars Fenneberg
5  *
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.
9  *
10  */
11 
12 #include "includes.h"
13 #include <unistd.h>
14 #include <fcntl.h>
15 
do_lock_exclusive(int fd)16 int do_lock_exclusive(int fd)
17 {
18 	struct flock fl;
19 	int res;
20 
21 	memset((void *)&fl, 0, sizeof(fl));
22 
23 	fl.l_type = F_WRLCK;
24 	fl.l_whence = fl.l_start = 0;
25 	fl.l_len = 0; /* 0 means "to end of file" */
26 
27 	res = fcntl(fd, F_SETLK, &fl);
28 
29 	if ((res == -1) && (errno == EAGAIN))
30 		errno = EWOULDBLOCK;
31 
32 	return res;
33 }
34 
do_unlock(int fd)35 int do_unlock(int fd)
36 {
37 	struct flock fl;
38 
39 	memset((void *)&fl, 0, sizeof(fl));
40 
41 	fl.l_type = F_UNLCK;
42 	fl.l_whence = fl.l_start = 0;
43 	fl.l_len = 0; /* 0 means "to end of file" */
44 
45 	return fcntl(fd, F_SETLK, &fl);
46 }
47