Public feed
#601381
diff --git a/src/iniparser.c b/src/iniparser.c
index 72e53af..2945bad 100644
--- a/src/iniparser.c
+++ b/src/iniparser.c
@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <fcntl.h>
#include "iniparser.h"
@@ -39,6 +40,21 @@
extern "C" {
#endif
+/* lock INI file */
+static void ini_file_set_lock (FILE *ini_file, unsigned int set_lock)
+{
+ int fd;
+ struct flock lockinfo;
+
+ fd = fileno (ini_file);
+
+ memset (&lockinfo, 0, sizeof (struct flock));
+ lockinfo.l_type = set_lock ? F_WRLCK : F_UNLCK;
+ lockinfo.l_pid = getpid();
+
+ fcntl (fd, F_SETLKW, &lockinfo);
+}
+
/* strlib.c following */
#define ASCIILINESZ 1024
@@ -532,6 +548,7 @@ void iniparser_dump_ini(dictionary * d, const char * file_name)
if (f==NULL)
return;
+ ini_file_set_lock (f, 1);
nsec = iniparser_getnsec(d);
if (nsec<1) {
/* No section in file: dump all keys as they are */
@@ -560,6 +577,7 @@ void iniparser_dump_ini(dictionary * d, const char * file_name)
fprintf(f, "\n");
}
+ ini_file_set_lock (f, 0);
fclose(f);
}
@@ -685,6 +703,7 @@ dictionary * iniparser_new(char *ininame)
return NULL ;
}
+ ini_file_set_lock (ini, 1);
sec[0]=0;
/*
@@ -720,6 +739,7 @@ dictionary * iniparser_new(char *ininame)
}
}
}
+ ini_file_set_lock (ini, 0);
fclose(ini);
return d ;
}