diff options
Diffstat (limited to 'nacl/curvecp/open_lock.c')
-rw-r--r-- | nacl/curvecp/open_lock.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/nacl/curvecp/open_lock.c b/nacl/curvecp/open_lock.c new file mode 100644 index 00000000..898f3b60 --- /dev/null +++ b/nacl/curvecp/open_lock.c | |||
@@ -0,0 +1,19 @@ | |||
1 | #include <sys/types.h> | ||
2 | #include <sys/stat.h> | ||
3 | #include <unistd.h> | ||
4 | #include <fcntl.h> | ||
5 | #include "open.h" | ||
6 | |||
7 | int open_lock(const char *fn) | ||
8 | { | ||
9 | #ifdef O_CLOEXEC | ||
10 | int fd = open(fn,O_RDWR | O_CLOEXEC); | ||
11 | if (fd == -1) return -1; | ||
12 | #else | ||
13 | int fd = open(fn,O_RDWR); | ||
14 | if (fd == -1) return -1; | ||
15 | fcntl(fd,F_SETFD,1); | ||
16 | #endif | ||
17 | if (lockf(fd,F_LOCK,0) == -1) { close(fd); return -1; } | ||
18 | return fd; | ||
19 | } | ||