From e149ee88cf53bb5665ab240a138be41d0b337ea8 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> Date: Fri, 25 May 2001 21:10:58 +0000 Subject: This commit was manufactured by cvs2svn to create tag 'v1_6_4_preview4'. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_6_4_preview4@1459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- missing/flock.c | 120 +++++++++++++++++++++++++++----------------------------- 1 file changed, 58 insertions(+), 62 deletions(-) (limited to 'missing/flock.c') diff --git a/missing/flock.c b/missing/flock.c index 78576d438c..c828fcc7ad 100644 --- a/missing/flock.c +++ b/missing/flock.c @@ -1,6 +1,55 @@ #include "config.h" -#if defined(HAVE_LOCKF) +#if defined HAVE_FCNTL && defined HAVE_FCNTL_H + +/* These are the flock() constants. Since this sytems doesn't have + flock(), the values of the constants are probably not available. +*/ +# ifndef LOCK_SH +# define LOCK_SH 1 +# endif +# ifndef LOCK_EX +# define LOCK_EX 2 +# endif +# ifndef LOCK_NB +# define LOCK_NB 4 +# endif +# ifndef LOCK_UN +# define LOCK_UN 8 +# endif + +#include +#include +#include + +int +flock(fd, operation) + int fd; + int operation; +{ + struct flock lock; + + switch (operation & ~LOCK_NB) { + case LOCK_SH: + lock.l_type = F_RDLCK; + break; + case LOCK_EX: + lock.l_type = F_WRLCK; + break; + case LOCK_UN: + lock.l_type = F_UNLCK; + break; + default: + errno = EINVAL; + return -1; + } + lock.l_whence = SEEK_SET; + lock.l_start = lock.l_len = 0L; + + return fcntl(fd, (operation & LOCK_NB) ? F_SETLK : F_SETLKW, &lock); +} + +#elif defined(HAVE_LOCKF) #include #include @@ -45,86 +94,33 @@ flock(fd, operation) int fd; int operation; { - int i; switch (operation) { /* LOCK_SH - get a shared lock */ case LOCK_SH: + rb_notimplement(); + return -1; /* LOCK_EX - get an exclusive lock */ case LOCK_EX: - i = lockf (fd, F_LOCK, 0); - break; + return lockf (fd, F_LOCK, 0); /* LOCK_SH|LOCK_NB - get a non-blocking shared lock */ case LOCK_SH|LOCK_NB: + rb_notimplement(); + return -1; /* LOCK_EX|LOCK_NB - get a non-blocking exclusive lock */ case LOCK_EX|LOCK_NB: - i = lockf (fd, F_TLOCK, 0); - if (i == -1) - if ((errno == EAGAIN) || (errno == EACCES)) - errno = EWOULDBLOCK; - break; + return lockf (fd, F_TLOCK, 0); /* LOCK_UN - unlock */ case LOCK_UN: - i = lockf (fd, F_ULOCK, 0); - break; + return lockf (fd, F_ULOCK, 0); /* Default - can't decipher operation */ default: - i = -1; errno = EINVAL; - break; + return -1; } - return i; -} -#elif defined HAVE_FCNTL && defined HAVE_FCNTL_H - -/* These are the flock() constants. Since this sytems doesn't have - flock(), the values of the constants are probably not available. -*/ -# ifndef LOCK_SH -# define LOCK_SH 1 -# endif -# ifndef LOCK_EX -# define LOCK_EX 2 -# endif -# ifndef LOCK_NB -# define LOCK_NB 4 -# endif -# ifndef LOCK_UN -# define LOCK_UN 8 -# endif - -#include -#include -#include - -int -flock(fd, operation) - int fd; - int operation; -{ - struct flock lock; - - switch (operation & ~LOCK_NB) { - case LOCK_SH: - lock.l_type = F_RDLCK; - break; - case LOCK_EX: - lock.l_type = F_WRLCK; - break; - case LOCK_UN: - lock.l_type = F_UNLCK; - break; - default: - errno = EINVAL; - return -1; - } - lock.l_whence = SEEK_SET; - lock.l_start = lock.l_len = 0L; - - return fcntl(fd, (operation & LOCK_NB) ? F_SETLK : F_SETLKW, &lock); } #elif !defined NT int -- cgit v1.2.3