mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-29 22:40:34 +02:00
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).
This commit is contained in:
parent
3731192f30
commit
837b0ae0b5
1 changed files with 1 additions and 71 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue