diff options
author | Reuben Thomas <rrt@sc3d.org> | 2017-02-04 19:07:35 +0000 |
---|---|---|
committer | Reuben Thomas <rrt@sc3d.org> | 2017-02-09 00:28:24 +0000 |
commit | edf662a5ec8db85aa6e5a5d00531ab6b8773131f (patch) | |
tree | 959c82306b64d1762bd13f28b494e693f1468ea1 /src/pwl.c | |
parent | 0115a4c6c76bffbb1bd6a6c2497fcec05304ce33 (diff) | |
download | enchant-edf662a5ec8db85aa6e5a5d00531ab6b8773131f.tar.gz |
Use gnulib to get cross-platform flock, and use it
Diffstat (limited to 'src/pwl.c')
-rw-r--r-- | src/pwl.c | 53 |
1 files changed, 3 insertions, 50 deletions
@@ -57,14 +57,9 @@ #include <string.h> #include <sys/types.h> #include <sys/stat.h> +#include <sys/file.h> #include <fcntl.h> -#ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#include <windows.h> -#include <io.h> -#endif - #include <glib.h> #include <glib/gstdio.h> #include "enchant-provider.h" @@ -75,11 +70,6 @@ #pragma warning(disable: 4996) /* The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name. */ #endif -#if defined(HAVE_FLOCK) || defined(HAVE_LOCKF) -#include <unistd.h> -#include <sys/file.h> -#endif /* HAVE_FLOCK || HAVE_LOCKF */ - #define ENCHANT_PWL_MAX_ERRORS 3 #define ENCHANT_PWL_MAX_SUGGS 15 @@ -192,45 +182,8 @@ static void enchant_trie_matcher_poppath(EnchantTrieMatcher* matcher,int num); static int edit_dist(const char* word1, const char* word2); -static void -enchant_lock_file (FILE * f) -{ -#if defined(HAVE_FLOCK) - flock (fileno (f), LOCK_EX); -#elif defined(HAVE_LOCKF) - lockf (fileno (f), F_LOCK, 0); -#elif defined(_WIN32) - OVERLAPPED overlapped; - - overlapped.Offset = 0; - overlapped.OffsetHigh = 0; - overlapped.hEvent = NULL; - if (!LockFileEx ((HANDLE) _get_osfhandle (fileno (f)), LOCKFILE_EXCLUSIVE_LOCK, 0, 0, 0x80000000, &overlapped)) - g_warning ("Could not lock file\n"); -#else - /* TODO: UNIX fcntl. This race condition probably isn't too bad. */ -#endif /* HAVE_FLOCK */ -} - -static void -enchant_unlock_file (FILE * f) -{ -#if defined(HAVE_FLOCK) - flock (fileno (f), LOCK_UN); -#elif defined(HAVE_LOCKF) - lockf (fileno (f), F_ULOCK, 0); -#elif defined(_WIN32) - OVERLAPPED overlapped; - - overlapped.Offset = 0; - overlapped.OffsetHigh = 0; - overlapped.hEvent = NULL; - if (!UnlockFileEx ((HANDLE) _get_osfhandle (fileno (f)), 0, 0, 0x80000000, &overlapped)) - g_warning ("Could not unlock file\n"); -#else - /* TODO: UNIX fcntl. This race condition probably isn't too bad. */ -#endif /* HAVE_FLOCK */ -} +#define enchant_lock_file(f) flock (fileno (f), LOCK_EX) +#define enchant_unlock_file(f) flock (fileno (f), LOCK_UN) /** * enchant_pwl_init |