diff options
author | Ludovic Courtès <ludo@gnu.org> | 2009-05-21 01:24:01 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2009-05-21 01:24:01 +0200 |
commit | 837b0ae0b5d530b0c254ebe331fb5ab1de3e7fe8 (patch) | |
tree | 6d4fd663d5a20ab08048d62ca155931f8f2e01b6 | |
parent | 3731192f30158c0c70d243ddeae87693fa37a0e4 (diff) | |
download | guile-837b0ae0b5d530b0c254ebe331fb5ab1de3e7fe8.tar.gz |
Make use of Gnulib's `flock' module.
* libguile/posix.c: Always use <sys/file.h>, which is provided by
Gnulib.
(flock)[__MINGW32__]: Remove.
(scm_flock): Compile unconditionally. Always use Gnulib's flock(2).
-rw-r--r-- | libguile/posix.c | 72 |
1 files changed, 1 insertions, 71 deletions
diff --git a/libguile/posix.c b/libguile/posix.c index 5f9b6cf8e..2799209d9 100644 --- a/libguile/posix.c +++ b/libguile/posix.c @@ -138,9 +138,7 @@ extern char ** environ; # include <sys/resource.h> #endif -#if HAVE_SYS_FILE_H -# include <sys/file.h> -#endif +#include <sys/file.h> /* from Gnulib */ #if HAVE_CRT_EXTERNS_H #include <crt_externs.h> /* for Darwin _NSGetEnviron */ @@ -1899,73 +1897,6 @@ SCM_DEFINE (scm_getpass, "getpass", 1, 0, 0, #undef FUNC_NAME #endif /* HAVE_GETPASS */ -/* Wrapper function for flock() support under M$-Windows. */ -#ifdef __MINGW32__ -# include <io.h> -# include <sys/locking.h> -# include <errno.h> -# ifndef _LK_UNLCK - /* Current MinGW package fails to define this. *sigh* */ -# define _LK_UNLCK 0 -# endif -# define LOCK_EX 1 -# define LOCK_UN 2 -# define LOCK_SH 4 -# define LOCK_NB 8 - -static int flock (int fd, int operation) -{ - long pos, len; - int ret, err; - - /* Disable invalid arguments. */ - if (((operation & (LOCK_EX | LOCK_SH)) == (LOCK_EX | LOCK_SH)) || - ((operation & (LOCK_EX | LOCK_UN)) == (LOCK_EX | LOCK_UN)) || - ((operation & (LOCK_SH | LOCK_UN)) == (LOCK_SH | LOCK_UN))) - { - errno = EINVAL; - return -1; - } - - /* Determine mode of operation and discard unsupported ones. */ - if (operation == (LOCK_NB | LOCK_EX)) - operation = _LK_NBLCK; - else if (operation & LOCK_UN) - operation = _LK_UNLCK; - else if (operation == LOCK_EX) - operation = _LK_LOCK; - else - { - errno = EINVAL; - return -1; - } - - /* Save current file pointer and seek to beginning. */ - if ((pos = lseek (fd, 0, SEEK_CUR)) == -1 || (len = filelength (fd)) == -1) - return -1; - lseek (fd, 0L, SEEK_SET); - - /* Deadlock if necessary. */ - do - { - ret = _locking (fd, operation, len); - } - while (ret == -1 && errno == EDEADLOCK); - - /* Produce meaningful error message. */ - if (errno == EACCES && operation == _LK_NBLCK) - err = EDEADLOCK; - else - err = errno; - - /* Return to saved file position pointer. */ - lseek (fd, pos, SEEK_SET); - errno = err; - return ret; -} -#endif /* __MINGW32__ */ - -#if HAVE_FLOCK || defined (__MINGW32__) SCM_DEFINE (scm_flock, "flock", 2, 0, 0, (SCM file, SCM operation), "Apply or remove an advisory lock on an open file.\n" @@ -2009,7 +1940,6 @@ SCM_DEFINE (scm_flock, "flock", 2, 0, 0, return SCM_UNSPECIFIED; } #undef FUNC_NAME -#endif /* HAVE_FLOCK */ #if HAVE_SETHOSTNAME SCM_DEFINE (scm_sethostname, "sethostname", 1, 0, 0, |