summaryrefslogtreecommitdiff
path: root/gnulib/lib/flock.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2018-05-28 13:57:20 +0100
committerColin Watson <cjwatson@debian.org>2018-05-28 13:57:20 +0100
commitccff906eeeeb1a3f0d694db8d890cfdf76f54a9a (patch)
tree58a7b7e3e93502a8530b06ac121d3c3b7c6fdcf4 /gnulib/lib/flock.c
parent4a9046a49184b6395965bd15dc57b50cc643e0c6 (diff)
Switch to bootstrap
We no longer keep autogenerated files in git. * .gitignore: Add **/Makefile, **/Makefile.in, /ABOUT-NLS, /aclocal.m4, /build-aux, /config.h.in, /configure, /gl, /gnulib, docs/INSTALL.autoconf, po/Makefile.in.in, po/Makevars, po/Rules-quot, po/boldquot.sed, po/en@boldquot.header, po/en@quot.header, po/insert-header.sin, po/quot.sed, and po/remove-potcdate.sin. Remove docs/Makefile, gnulib/*, init/Makefile, init/systemd/Makefile, lib/Makefile, libdb/Makefile, man/Makefile, man/*/Makefile, manual/Makefile, po/Makefile, po/Makefile.in, src/Makefile, src/tests/Makefile, and tools/Makefile. * ABOUT-NLS, Makefile.in, aclocal.m4, autogen.sh, build-aux, config.h.in, configure, docs/INSTALL.autoconf, docs/Makefile.in, gnulib, init/Makefile.in, init/systemd/Makefile.in, lib/Makefile.in, libdb/Makefile.in, man/Makefile.in, man/da/Makefile.in, man/de/Makefile.in, man/es/Makefile.in, man/fr/Makefile.in, man/id/Makefile.in, man/it/Makefile.in, man/ja/Makefile.in, man/nl/Makefile.in, man/pl/Makefile.in, man/po4a/Makefile.in, man/pt_BR/Makefile.in, man/ru/Makefile.in, man/sr/Makefile.in, man/sv/Makefile.in, man/tr/Makefile.in, man/zh_CN/Makefile.in, manual/Makefile.in, po/Makefile.in.in, po/Makevars, po/Rules-quot, po/boldquot.sed, po/en@boldquot.header, po/en@quot.header, po/insert-header.sin, po/quot.sed, po/remove-potcdate.sin, src/Makefile.in, src/tests/Makefile.in, tools/Makefile.in: Remove. * bootstrap, bootstrap.conf: New files. * Makefile.am (GNULIB_PO, SUBDIRS, EXTRA_DIST, ACLOCAL_AMFLAGS): Refer to gl/ rather than gnulib/ (gnulib/ now contains pristine source). (EXTRA_DIST): Replace autogen.sh with bootstrap and bootstrap.conf. Replace gnulib/argp-domain.patch with patches/argp-domain.patch. Add patches/fdutimens-hurd.patch. Remove gnulib/m4/gnulib-cache.m4 and gnulib/m4/gnulib-tool.m4. * gnulib/argp-domain.patch: Rename to ... * patches/argp-domain.patch: ... this. Update target paths. * gnulib/fdutimens-hurd.patch: Rename to ... * patches/fdutimens-hurd.patch: ... this. Update target paths. * configure.ac (AM_GNU_GETTEXT_VERSION): Upgrade to 0.18.3, for compatibility with current Automake. (HAVE_GNULIB_PO, AC_CONFIG_FILES): Refer to gl/ rather than gnulib/. * lib/Makefile.am (libman_la_CPPFLAGS, libman_la_LIBADD): Likewise. * libdb/Makefile.am (libmandb_la_CPPFLAGS): Likewise. * src/Makefile.am (AM_CPPFLAGS, LIBMAN): Likewise. * src/tests/Makefile.am (AM_CPPFLAGS, fspause_LDADD): Likewise. * docs/HACKING: Describe new policy. * release.sh: Call ./bootstrap rather than ./autogen.sh.
Diffstat (limited to 'gnulib/lib/flock.c')
-rw-r--r--gnulib/lib/flock.c220
1 files changed, 0 insertions, 220 deletions
diff --git a/gnulib/lib/flock.c b/gnulib/lib/flock.c
deleted file mode 100644
index 1a667a50..00000000
--- a/gnulib/lib/flock.c
+++ /dev/null
@@ -1,220 +0,0 @@
-/* Emulate flock on platforms that lack it, primarily Windows and MinGW.
-
- This is derived from sqlite3 sources.
- http://www.sqlite.org/cvstrac/rlog?f=sqlite/src/os_win.c
- http://www.sqlite.org/copyright.html
-
- Written by Richard W.M. Jones <rjones.at.redhat.com>
-
- Copyright (C) 2008-2014 Free Software Foundation, Inc.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public
- License as published by the Free Software Foundation; either
- version 3 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include <sys/file.h>
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-
-/* LockFileEx */
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
-
-# include <errno.h>
-
-/* _get_osfhandle */
-# include "msvc-nothrow.h"
-
-/* Determine the current size of a file. Because the other braindead
- * APIs we'll call need lower/upper 32 bit pairs, keep the file size
- * like that too.
- */
-static BOOL
-file_size (HANDLE h, DWORD * lower, DWORD * upper)
-{
- *lower = GetFileSize (h, upper);
- return 1;
-}
-
-/* LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems. */
-# ifndef LOCKFILE_FAIL_IMMEDIATELY
-# define LOCKFILE_FAIL_IMMEDIATELY 1
-# endif
-
-/* Acquire a lock. */
-static BOOL
-do_lock (HANDLE h, int non_blocking, int exclusive)
-{
- BOOL res;
- DWORD size_lower, size_upper;
- OVERLAPPED ovlp;
- int flags = 0;
-
- /* We're going to lock the whole file, so get the file size. */
- res = file_size (h, &size_lower, &size_upper);
- if (!res)
- return 0;
-
- /* Start offset is 0, and also zero the remaining members of this struct. */
- memset (&ovlp, 0, sizeof ovlp);
-
- if (non_blocking)
- flags |= LOCKFILE_FAIL_IMMEDIATELY;
- if (exclusive)
- flags |= LOCKFILE_EXCLUSIVE_LOCK;
-
- return LockFileEx (h, flags, 0, size_lower, size_upper, &ovlp);
-}
-
-/* Unlock reader or exclusive lock. */
-static BOOL
-do_unlock (HANDLE h)
-{
- int res;
- DWORD size_lower, size_upper;
-
- res = file_size (h, &size_lower, &size_upper);
- if (!res)
- return 0;
-
- return UnlockFile (h, 0, 0, size_lower, size_upper);
-}
-
-/* Now our BSD-like flock operation. */
-int
-flock (int fd, int operation)
-{
- HANDLE h = (HANDLE) _get_osfhandle (fd);
- DWORD res;
- int non_blocking;
-
- if (h == INVALID_HANDLE_VALUE)
- {
- errno = EBADF;
- return -1;
- }
-
- non_blocking = operation & LOCK_NB;
- operation &= ~LOCK_NB;
-
- switch (operation)
- {
- case LOCK_SH:
- res = do_lock (h, non_blocking, 0);
- break;
- case LOCK_EX:
- res = do_lock (h, non_blocking, 1);
- break;
- case LOCK_UN:
- res = do_unlock (h);
- break;
- default:
- errno = EINVAL;
- return -1;
- }
-
- /* Map Windows errors into Unix errnos. As usual MSDN fails to
- * document the permissible error codes.
- */
- if (!res)
- {
- DWORD err = GetLastError ();
- switch (err)
- {
- /* This means someone else is holding a lock. */
- case ERROR_LOCK_VIOLATION:
- errno = EAGAIN;
- break;
-
- /* Out of memory. */
- case ERROR_NOT_ENOUGH_MEMORY:
- errno = ENOMEM;
- break;
-
- case ERROR_BAD_COMMAND:
- errno = EINVAL;
- break;
-
- /* Unlikely to be other errors, but at least don't lose the
- * error code.
- */
- default:
- errno = err;
- }
-
- return -1;
- }
-
- return 0;
-}
-
-#else /* !Windows */
-
-# ifdef HAVE_STRUCT_FLOCK_L_TYPE
-/* We know how to implement flock in terms of fcntl. */
-
-# include <fcntl.h>
-
-# ifdef HAVE_UNISTD_H
-# include <unistd.h>
-# endif
-
-# include <errno.h>
-# include <string.h>
-
-int
-flock (int fd, int operation)
-{
- int cmd, r;
- struct flock fl;
-
- if (operation & LOCK_NB)
- cmd = F_SETLK;
- else
- cmd = F_SETLKW;
- operation &= ~LOCK_NB;
-
- memset (&fl, 0, sizeof fl);
- fl.l_whence = SEEK_SET;
- /* l_start & l_len are 0, which as a special case means "whole file". */
-
- switch (operation)
- {
- case LOCK_SH:
- fl.l_type = F_RDLCK;
- break;
- case LOCK_EX:
- fl.l_type = F_WRLCK;
- break;
- case LOCK_UN:
- fl.l_type = F_UNLCK;
- break;
- default:
- errno = EINVAL;
- return -1;
- }
-
- r = fcntl (fd, cmd, &fl);
- if (r == -1 && errno == EACCES)
- errno = EAGAIN;
-
- return r;
-}
-
-# else /* !HAVE_STRUCT_FLOCK_L_TYPE */
-
-# error "This platform lacks flock function, and Gnulib doesn't provide a replacement. This is a bug in Gnulib."
-
-# endif /* !HAVE_STRUCT_FLOCK_L_TYPE */
-
-#endif /* !Windows */