xref: /minix/minix/lib/libc/sys/flock.c (revision 83133719)
1 /* Library routines
2  *
3  * Porting to Minix 2.0.0
4  * Author:	Giovanni Falzoni <gfalzoni@pointest.com>
5  */
6 
7 #include <sys/cdefs.h>
8 #include "namespace.h"
9 #include <lib.h>
10 
11 #include <sys/types.h>
12 #include <fcntl.h>
13 #include <string.h>
14 #include <errno.h>
15 #include <unistd.h>
16 
17 /*
18  *	Name:		int flock(int fd, int mode);
19  *	Function:	Implements the flock function in Minix.
20  */
21 int flock(int fd, int mode)
22 {
23   struct flock lck;
24   register int retcode;
25 
26   memset((void *) &lck, 0, sizeof(struct flock));
27   lck.l_type = mode & ~LOCK_NB;
28   lck.l_pid = getpid();
29   if ((retcode = fcntl(fd, mode & LOCK_NB ? F_SETLK : F_SETLKW, &lck)) < 0 && errno == EAGAIN)
30 	errno = EWOULDBLOCK;
31   return retcode;
32 }
33 
34 /** flock.c **/
35