From: Daniel Carl <danielcarl@gmx.de>
Date: Wed, 9 Apr 2014 21:06:42 +0000 (+0200)
Subject: Removed obsolete FILE_LOCK_SET macro.
X-Git-Url: https://git.owens.tech///git?a=commitdiff_plain;h=13296a8d0dfe86793fe6507e4da05047e3d47c51;p=vimb.git

Removed obsolete FILE_LOCK_SET macro.
---

diff --git a/src/history.c b/src/history.c
index 314a62d..ae96f19 100644
--- a/src/history.c
+++ b/src/history.c
@@ -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);
     }
 }
diff --git a/src/main.h b/src/main.h
index b40b8e4..5609edd 100644
--- a/src/main.h
+++ b/src/main.h
@@ -66,12 +66,6 @@
 #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))
diff --git a/src/util.c b/src/util.c
index f4e9bb6..253ef8f 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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;