File: lock.c

package info (click to toggle)
axmail 2.13-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 544 kB
  • sloc: ansic: 2,489; sh: 263; makefile: 49
file content (35 lines) | stat: -rw-r--r-- 463 bytes parent folder | download | duplicates (4)
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

/* lock.c - file locking services */

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdarg.h>
#include <sys/file.h>

#include "lock.h"
#include "utils.h"

/* Lock a file descriptor. */

int lock_fd(int fd)
{
	if (flock(fd, LOCK_EX)) {
		syserr("Can't lock fd\n");
		return -1;
	}

	return 0;
}

/* Unlock a file descriptor. */

int unlock_fd(int fd)
{
	if (flock(fd, LOCK_UN)) {
		syserr("Can't unlockfd\n");
		return -1;
	}

	return 0;
}