Written by Richard W.M. Jones <rjones.at.redhat.com>
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008-2012 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
+ You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-/* _get_osfhandle */
-#include <io.h>
-
/* LockFileEx */
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
-#include <errno.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
}
/* LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems. */
-#ifndef LOCKFILE_FAIL_IMMEDIATELY
-# define LOCKFILE_FAIL_IMMEDIATELY 1
-#endif
+# ifndef LOCKFILE_FAIL_IMMEDIATELY
+# define LOCKFILE_FAIL_IMMEDIATELY 1
+# endif
/* Acquire a lock. */
static BOOL
{
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;
- }
+ {
+ /* 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;
}
#else /* !Windows */
-#ifdef HAVE_FLOCK_L_TYPE
+# ifdef HAVE_STRUCT_FLOCK_L_TYPE
/* We know how to implement flock in terms of fcntl. */
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
+# include <fcntl.h>
+
+# ifdef HAVE_UNISTD_H
+# include <unistd.h>
+# endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
+# include <errno.h>
+# include <string.h>
int
flock (int fd, int operation)
return r;
}
-#else /* !HAVE_FLOCK_L_TYPE */
+# 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."
+# error "This platform lacks flock function, and Gnulib doesn't provide a replacement. This is a bug in Gnulib."
-#endif /* !HAVE_FLOCK_L_TYPE */
+# endif /* !HAVE_STRUCT_FLOCK_L_TYPE */
#endif /* !Windows */