minix/lib/nbsd_libc/sys-minix/flock.c
Gianluca Guida 4f294c247f Add NBSDLibc Minix specific files.
This patch mainly copies and modifies files existing in
the current libc implementing minix specific functions.

To keep consisten with the NetBSD libc, we remove 
namespace stubs and we use "namespace.h" and weak
links.
2011-02-17 17:11:09 +00:00

39 lines
762 B
C

/* 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>
#ifdef __weak_alias
__weak_alias(flock, _flock)
#endif
/*
* 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 **/