Another try to fixed FreeBSD compile error (#76).
authorDaniel Carl <danielcarl@gmx.de>
Fri, 11 Apr 2014 19:54:11 +0000 (21:54 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Fri, 11 Apr 2014 19:54:11 +0000 (21:54 +0200)
config.mk
src/history.c
src/main.h
src/session.c
src/util.c

index a541203..79a0c34 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -30,7 +30,7 @@ PROJECT_UCFIRST = $(shell echo '${PROJECT}' | awk '{for(i=1;i<=NF;i++){$$i=toupp
 
 CPPFLAGS  = -DVERSION=\"${VERSION}\"
 CPPFLAGS += -DPROJECT=\"${PROJECT}\" -DPROJECT_UCFIRST=\"${PROJECT_UCFIRST}\"
-CPPFLAGS += -D_BSD_SOURCE -D_XOPEN_SOURCE=500
+CPPFLAGS += -D_XOPEN_SOURCE=500
 ifeq ($(USEGTK3), 1)
 CPPFLAGS += -DHAS_GTK3
 endif
@@ -40,7 +40,7 @@ LIBFLAGS = $(shell pkg-config --libs $(LIBS))
 
 # normal compiler flags
 CFLAGS  += $(shell pkg-config --cflags $(LIBS))
-CFLAGS  += -Wall -pipe -ansi -std=c99 -pedantic
+CFLAGS  += -Wall -pipe -std=c99 -pedantic
 CFLAGS  += -Wmissing-declarations -Wmissing-parameter-type -Wno-overlength-strings
 CFLAGS  += ${CPPFLAGS}
 LDFLAGS += ${LIBFLAGS}
index e274412..c3cb17b 100644 (file)
@@ -18,8 +18,6 @@
  */
 
 #include "config.h"
-#include <fcntl.h>
-#include <sys/file.h>
 #include "main.h"
 #include "history.h"
 #include "util.h"
@@ -212,7 +210,7 @@ static void write_to_file(GList *list, const char *file)
 {
     FILE *f;
     if ((f = fopen(file, "w"))) {
-        flock(fileno(f), LOCK_EX);
+        FLOCK(fileno(f), F_WRLCK);
 
         /* overwrite the history file with new unique history items */
         for (GList *link = list; link; link = link->next) {
@@ -224,7 +222,7 @@ static void write_to_file(GList *list, const char *file)
             }
         }
 
-        flock(fileno(f), LOCK_UN);
+        FLOCK(fileno(f), F_UNLCK);
         fclose(f);
     }
 }
index 5609edd..de50539 100644 (file)
 /* check if the char x is a char with CTRL like ^C */
 #define IS_CTRL(x)   (((guchar)x) <= 0x1f)
 
+#define FLOCK(fd, cmd) { \
+    struct flock lock = {.l_type=cmd,.l_start=0,.l_whence=SEEK_SET,.l_len=0}; \
+    fcntl(fd, F_SETLK, lock); \
+}
+
 #ifdef DEBUG
 #define PRINT_DEBUG(...) { \
     fprintf(stderr, "\n\033[31;1mDEBUG:\033[0m %s:%d:%s()\t", __FILE__, __LINE__, __func__); \
index 8033439..b42f697 100644 (file)
@@ -18,8 +18,6 @@
  */
 
 #include "config.h"
-#include <fcntl.h>
-#include <sys/file.h>
 #include "main.h"
 #include "session.h"
 
@@ -82,7 +80,7 @@ static SoupCookieJar *cookiejar_new(const char *file, gboolean ro)
 
 static void cookiejar_changed(SoupCookieJar *self, SoupCookie *old_cookie, SoupCookie *new_cookie)
 {
-    flock(COOKIEJAR(self)->lock, LOCK_EX);
+    FLOCK(COOKIEJAR(self)->lock, F_WRLCK);
     SoupDate *expire;
     if (new_cookie && !new_cookie->expires && vb.config.cookie_timeout) {
         expire = soup_date_new_from_now(vb.config.cookie_timeout);
@@ -90,7 +88,7 @@ static void cookiejar_changed(SoupCookieJar *self, SoupCookie *old_cookie, SoupC
         soup_date_free(expire);
     }
     SOUP_COOKIE_JAR_CLASS(cookiejar_parent_class)->changed(self, old_cookie, new_cookie);
-    flock(COOKIEJAR(self)->lock, LOCK_UN);
+    FLOCK(COOKIEJAR(self)->lock, F_UNLCK);
 }
 
 static void cookiejar_class_init(CookieJarClass *class)
@@ -116,8 +114,8 @@ static void cookiejar_init(CookieJar *self)
 static void cookiejar_set_property(GObject *self, guint prop_id, const
     GValue *value, GParamSpec *pspec)
 {
-    flock(COOKIEJAR(self)->lock, LOCK_SH);
+    FLOCK(COOKIEJAR(self)->lock, F_RDLCK);
     G_OBJECT_CLASS(cookiejar_parent_class)->set_property(self, prop_id, value, pspec);
-    flock(COOKIEJAR(self)->lock, LOCK_UN);
+    FLOCK(COOKIEJAR(self)->lock, F_UNLCK);
 }
 #endif
index ab958b5..f4ecfe3 100644 (file)
  */
 
 #include "config.h"
-#include <fcntl.h>
-#include <sys/file.h>
 #include <stdio.h>
 #include <pwd.h>
 #include <ctype.h>
+#include "main.h"
 #include "util.h"
 #include "ascii.h"
 
@@ -170,13 +169,13 @@ gboolean util_file_append(const char *file, const char *format, ...)
     FILE *f;
 
     if ((f = fopen(file, "a+"))) {
-        flock(fileno(f), LOCK_EX);
+        FLOCK(fileno(f), F_WRLCK);
 
         va_start(args, format);
         vfprintf(f, format, args);
         va_end(args);
 
-        flock(fileno(f), LOCK_UN);
+        FLOCK(fileno(f), F_UNLCK);
         fclose(f);
 
         return true;
@@ -199,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"))) {
-        flock(fileno(f), LOCK_EX);
+        FLOCK(fileno(f), F_WRLCK);
 
         va_start(args, format);
         /* write new content to the file */
@@ -209,7 +208,7 @@ gboolean util_file_prepend(const char *file, const char *format, ...)
         /* append previous file content */
         fputs(content, f);
 
-        flock(fileno(f), LOCK_UN);
+        FLOCK(fileno(f), F_UNLCK);
         fclose(f);
 
         res = true;