summaryrefslogtreecommitdiff
path: root/src/lock.c
blob: cec290e3e427013495fb41f1ae3fd9c52cc7fceb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "lock.h"

#include <fcntl.h>
#include <sys/file.h>
#include <sys/types.h>
#include <unistd.h>

/**
	@file lock.c
	@author djb
	@source qmail
	@brief locking of resources
*/

#ifdef HASFLOCK
int lock_ex(int fd)
{
  return flock(fd, LOCK_EX);
}
int lock_exnb(int fd)
{
  return flock(fd, LOCK_EX | LOCK_NB);
}
int lock_un(int fd)
{
  return flock(fd, LOCK_UN);
}
#else
int lock_ex(int fd)
{
  return lockf(fd, 1, 0);
}
int lock_exnb(int fd)
{
  return lockf(fd, 2, 0);
}
int lock_un(int fd)
{
  return lockf(fd, 0, 0);
}
#endif