Removed obsolete FILE_LOCK_SET macro.
authorDaniel Carl <danielcarl@gmx.de>
Wed, 9 Apr 2014 21:06:42 +0000 (23:06 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Wed, 9 Apr 2014 21:06:42 +0000 (23:06 +0200)
src/history.c
src/main.h
src/util.c

index 314a62d..ae96f19 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include "config.h"
+#include <sys/file.h>
 #include "main.h"
 #include "history.h"
 #include "util.h"
@@ -210,7 +211,7 @@ static void write_to_file(GList *list, const char *file)
 {
     FILE *f;
     if ((f = fopen(file, "w"))) {
-        FILE_LOCK_SET(fileno(f), F_WRLCK);
+        flock(fileno(f), LOCK_EX);
 
         /* overwrite the history file with new unique history items */
         for (GList *link = list; link; link = link->next) {
@@ -222,7 +223,7 @@ static void write_to_file(GList *list, const char *file)
             }
         }
 
-        FILE_LOCK_SET(fileno(f), F_UNLCK);
+        flock(fileno(f), LOCK_UN);
         fclose(f);
     }
 }
index b40b8e4..5609edd 100644 (file)
 #define OVERWRITE_STRING(t, s) {if (t) {g_free(t); t = NULL;} t = g_strdup(s);}
 #define OVERWRITE_NSTRING(t, s, l) {if (t) {g_free(t); t = NULL;} t = g_strndup(s, l);}
 
-#define FILE_LOCK_SET(fd, cmd) \
-{ \
-    struct flock lock = { .l_type = cmd, .l_start = 0, .l_whence = SEEK_SET, .l_len = 0}; \
-    fcntl(fd, F_SETLK, lock); \
-}
-
 #ifdef HAS_GTK3
 #define VbColor GdkRGBA
 #define VB_COLOR_PARSE(color, string)   (gdk_rgba_parse(color, string))
index f4e9bb6..253ef8f 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include "config.h"
+#include <sys/file.h>
 #include <stdio.h>
 #include <pwd.h>
 #include <ctype.h>
@@ -168,13 +169,13 @@ gboolean util_file_append(const char *file, const char *format, ...)
     FILE *f;
 
     if ((f = fopen(file, "a+"))) {
-        FILE_LOCK_SET(fileno(f), F_WRLCK);
+        flock(fileno(f), LOCK_EX);
 
         va_start(args, format);
         vfprintf(f, format, args);
         va_end(args);
 
-        FILE_LOCK_SET(fileno(f), F_UNLCK);
+        flock(fileno(f), LOCK_UN);
         fclose(f);
 
         return true;
@@ -197,7 +198,7 @@ gboolean util_file_prepend(const char *file, const char *format, ...)
 
     content = util_get_file_contents(file, NULL);
     if ((f = fopen(file, "w"))) {
-        FILE_LOCK_SET(fileno(f), F_WRLCK);
+        flock(fileno(f), LOCK_EX);
 
         va_start(args, format);
         /* write new content to the file */
@@ -207,7 +208,7 @@ gboolean util_file_prepend(const char *file, const char *format, ...)
         /* append previous file content */
         fputs(content, f);
 
-        FILE_LOCK_SET(fileno(f), F_UNLCK);
+        flock(fileno(f), LOCK_UN);
         fclose(f);
 
         res = true;