*/
#include "config.h"
+#include <sys/file.h>
#include "main.h"
#include "history.h"
#include "util.h"
{
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) {
}
}
- FILE_LOCK_SET(fileno(f), F_UNLCK);
+ flock(fileno(f), LOCK_UN);
fclose(f);
}
}
#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))
*/
#include "config.h"
+#include <sys/file.h>
#include <stdio.h>
#include <pwd.h>
#include <ctype.h>
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;
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 */
/* append previous file content */
fputs(content, f);
- FILE_LOCK_SET(fileno(f), F_UNLCK);
+ flock(fileno(f), LOCK_UN);
fclose(f);
res = true;