| 1 |
/* |
| 2 |
* Copyright (C) 1997 Lars Fenneberg |
| 3 |
* |
| 4 |
* See the file COPYRIGHT for the respective terms and conditions. |
| 5 |
* If the file is missing contact me at [email protected] |
| 6 |
* and I'll send you a copy. |
| 7 |
* |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "includes.h" |
| 11 |
#include <unistd.h> |
| 12 |
#include <fcntl.h> |
| 13 |
|
| 14 |
int do_lock_exclusive(int fd) |
| 15 |
{ |
| 16 |
struct flock fl; |
| 17 |
int res; |
| 18 |
|
| 19 |
memset((void *)&fl, 0, sizeof(fl)); |
| 20 |
|
| 21 |
fl.l_type = F_WRLCK; |
| 22 |
fl.l_whence = fl.l_start = 0; |
| 23 |
fl.l_len = 0; /* 0 means "to end of file" */ |
| 24 |
|
| 25 |
res = fcntl(fd, F_SETLK, &fl); |
| 26 |
|
| 27 |
if ((res == -1) && (errno == EAGAIN)) |
| 28 |
errno = EWOULDBLOCK; |
| 29 |
|
| 30 |
return res; |
| 31 |
} |
| 32 |
|
| 33 |
int do_unlock(int fd) |
| 34 |
{ |
| 35 |
struct flock fl; |
| 36 |
|
| 37 |
memset((void *)&fl, 0, sizeof(fl)); |
| 38 |
|
| 39 |
fl.l_type = F_UNLCK; |
| 40 |
fl.l_whence = fl.l_start = 0; |
| 41 |
fl.l_len = 0; /* 0 means "to end of file" */ |
| 42 |
|
| 43 |
return fcntl(fd, F_SETLK, &fl); |
| 44 |
} |