etc/services - sync with NetBSD-8
[minix.git] / minix / lib / libc / sys / flock.c
blobe0249f5c69af457edb8e4d69f8c76e8528d03a32
1 /* Library routines
3 * Porting to Minix 2.0.0
4 * Author: Giovanni Falzoni <gfalzoni@pointest.com>
5 */
7 #include <sys/cdefs.h>
8 #include "namespace.h"
9 #include <lib.h>
11 #include <sys/types.h>
12 #include <fcntl.h>
13 #include <string.h>
14 #include <errno.h>
15 #include <unistd.h>
18 * Name: int flock(int fd, int mode);
19 * Function: Implements the flock function in Minix.
21 int flock(int fd, int mode)
23 struct flock lck;
25 memset((void *) &lck, 0, sizeof(struct flock));
26 switch (mode & ~LOCK_NB) {
27 case LOCK_SH: lck.l_type = F_RDLCK; break;
28 case LOCK_EX: lck.l_type = F_WRLCK; break;
29 case LOCK_UN: lck.l_type = F_UNLCK; break;
30 default: errno = EINVAL; return -1;
32 return fcntl(fd, mode & LOCK_NB ? F_SETLK : F_SETLKW, &lck);
35 /** flock.c **/