summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDom Lachowicz <domlachowicz@gmail.com>2003-08-25 18:28:16 +0000
committerDom Lachowicz <domlachowicz@gmail.com>2003-08-25 18:28:16 +0000
commit4c40193eea2f4eae0796fa6bf173427cadfc9493 (patch)
treee3e0b22d6e7c00b3a684e021f563a46acf374df2
parent54bd2b535ac631d722c3d662806ef7e348f79aa3 (diff)
downloadenchant-4c40193eea2f4eae0796fa6bf173427cadfc9493.tar.gz
personal dictionary file locks in place
git-svn-id: svn+ssh://svn.abisource.com/svnroot/enchant/trunk@20815 bcba8976-2d24-0410-9c9c-aab3bd5fdfd6
-rw-r--r--src/enchant.c49
1 files changed, 33 insertions, 16 deletions
diff --git a/src/enchant.c b/src/enchant.c
index d53536e..f478181 100644
--- a/src/enchant.c
+++ b/src/enchant.c
@@ -32,7 +32,9 @@
#include <stdlib.h>
#include <string.h>
-/* #include <sys/file.h> // only needed if we use flock() below */
+#if HAVE_FLOCK || HAVE_LOCKF
+#include <sys/file.h>
+#endif /* HAVE_FLOCK */
#include <glib.h>
#include <gmodule.h>
@@ -42,6 +44,30 @@
ENCHANT_PLUGIN_DECLARE("Enchant")
+static void
+enchant_lock_file (FILE * f)
+{
+#if HAVE_FLOCK
+ flock (fileno (f), LOCK_EX);
+#elif HAVE_LOCKF
+ lockf (fileno (f), F_LOCK, 0);
+#else
+ /* TODO: win32, UNIX fcntl */
+#endif /* HAVE_FLOCK */
+}
+
+static void
+enchant_unlock_file (FILE * f)
+{
+#if HAVE_FLOCK
+ flock (fileno (f), LOCK_UN);
+#elif HAVE_LOCKF
+ lockf (fileno (f), F_ULOCK, 0);
+#else
+ /* TODO: win32, UNIX fcntl */
+#endif /* HAVE_FLOCK */
+}
+
static char *
enchant_get_registry_value_ex (int current_user, const char * const prefix, const char * const key)
{
@@ -182,18 +208,13 @@ enchant_session_new (EnchantProvider *provider, const char * const lang)
/* populate personal filename */
f = fopen (session->personal_filename, "r");
if (f) {
-#if 0
- flock(fileno(f), LOCK_EX);
-#endif
-
+ enchant_lock_file (f);
+
while (NULL != (fgets (line, sizeof (line), f))) {
g_hash_table_insert (session->personal, g_strdup (line), GINT_TO_POINTER(TRUE));
}
-#if 0
- flock(fileno(f), LOCK_UN);
-#endif
-
+ enchant_unlock_file (f);
fclose (f);
}
}
@@ -218,17 +239,13 @@ enchant_session_add_personal (EnchantSession * session, const char * const word,
f = fopen (session->personal_filename, "a");
if (f) {
-#if 0
- flock(fileno(f), LOCK_EX);
-#endif
-
+ enchant_lock_file (f);
+
fwrite (word, sizeof(char), len, f);
fwrite ("\n", sizeof(char), 1, f);
fclose (f);
-#if 0
- flock(fileno(f), LOCK_UN);
-#endif
+ enchant_unlock_file (f);
}
}
}