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;
}
|