xref: /minix3/minix/lib/libc/sys/flock.c (revision 9488aa4c0452da1852a4f48bfad3c378d2b3e6cf)
1433d6423SLionel Sambuc /* Library routines
2433d6423SLionel Sambuc  *
3433d6423SLionel Sambuc  * Porting to Minix 2.0.0
4433d6423SLionel Sambuc  * Author:	Giovanni Falzoni <gfalzoni@pointest.com>
5433d6423SLionel Sambuc  */
6433d6423SLionel Sambuc 
7433d6423SLionel Sambuc #include <sys/cdefs.h>
8433d6423SLionel Sambuc #include "namespace.h"
9433d6423SLionel Sambuc #include <lib.h>
10433d6423SLionel Sambuc 
11433d6423SLionel Sambuc #include <sys/types.h>
12433d6423SLionel Sambuc #include <fcntl.h>
13433d6423SLionel Sambuc #include <string.h>
14433d6423SLionel Sambuc #include <errno.h>
15433d6423SLionel Sambuc #include <unistd.h>
16433d6423SLionel Sambuc 
17433d6423SLionel Sambuc /*
18433d6423SLionel Sambuc  *	Name:		int flock(int fd, int mode);
19433d6423SLionel Sambuc  *	Function:	Implements the flock function in Minix.
20433d6423SLionel Sambuc  */
flock(int fd,int mode)21433d6423SLionel Sambuc int flock(int fd, int mode)
22433d6423SLionel Sambuc {
23433d6423SLionel Sambuc   struct flock lck;
24433d6423SLionel Sambuc 
25433d6423SLionel Sambuc   memset((void *) &lck, 0, sizeof(struct flock));
26*9488aa4cSDavid van Moolenbroek   switch (mode & ~LOCK_NB) {
27*9488aa4cSDavid van Moolenbroek   case LOCK_SH: lck.l_type = F_RDLCK; break;
28*9488aa4cSDavid van Moolenbroek   case LOCK_EX: lck.l_type = F_WRLCK; break;
29*9488aa4cSDavid van Moolenbroek   case LOCK_UN: lck.l_type = F_UNLCK; break;
30*9488aa4cSDavid van Moolenbroek   default: errno = EINVAL; return -1;
31*9488aa4cSDavid van Moolenbroek   }
32*9488aa4cSDavid van Moolenbroek   return fcntl(fd, mode & LOCK_NB ? F_SETLK : F_SETLKW, &lck);
33433d6423SLionel Sambuc }
34433d6423SLionel Sambuc 
35433d6423SLionel Sambuc /** flock.c **/
36