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 */ flock(int fd,int mode)21int flock(int fd, int mode) 22 { 23 struct flock lck; 24 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; 31 } 32 return fcntl(fd, mode & LOCK_NB ? F_SETLK : F_SETLKW, &lck); 33 } 34 35 /** flock.c **/ 36