forked from Stichting-MINIX-Research-Foundation/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflock.c
More file actions
34 lines (29 loc) · 706 Bytes
/
Copy pathflock.c
File metadata and controls
34 lines (29 loc) · 706 Bytes
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
/* Library routines
*
* Porting to Minix 2.0.0
* Author: Giovanni Falzoni <gfalzoni@pointest.com>
*/
#include <sys/cdefs.h>
#include "namespace.h"
#include <lib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
/*
* Name: int flock(int fd, int mode);
* Function: Implements the flock function in Minix.
*/
int flock(int fd, int mode)
{
struct flock lck;
register int retcode;
memset((void *) &lck, 0, sizeof(struct flock));
lck.l_type = mode & ~LOCK_NB;
lck.l_pid = getpid();
if ((retcode = fcntl(fd, mode & LOCK_NB ? F_SETLK : F_SETLKW, &lck)) < 0 && errno == EAGAIN)
errno = EWOULDBLOCK;
return retcode;
}
/** flock.c **/