summaryrefslogtreecommitdiffstats
path: root/src/util/os_file.c
diff options
context:
space:
mode:
authorEric Engestrom <[email protected]>2019-06-03 17:51:37 +0100
committerEric Engestrom <[email protected]>2019-06-28 23:37:49 +0100
commit1b259f1ae798099de280dd0ee10018d1fd54be04 (patch)
tree60c81faad0c84205836ebb974c5b07a3acc64a76 /src/util/os_file.c
parent9de4325b27934f0ad944b78e9200cd09d8d8cd14 (diff)
util: add os_file_create_unique()
Signed-off-by: Eric Engestrom <[email protected]> Reviewed-by: Kristian H. Kristensen <[email protected]> Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/util/os_file.c')
-rw-r--r--src/util/os_file.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/util/os_file.c b/src/util/os_file.c
index 756164c3dfe..ae41506332d 100644
--- a/src/util/os_file.c
+++ b/src/util/os_file.c
@@ -6,7 +6,30 @@
#include "os_file.h"
#include <errno.h>
+#include <fcntl.h>
#include <stdlib.h>
+#include <sys/stat.h>
+
+
+#if defined(WIN32)
+#include <io.h>
+#define open _open
+#define fdopen _fdopen
+#define O_CREAT _O_CREAT
+#define O_EXCL _O_EXCL
+#define O_WRONLY _O_WRONLY
+#endif
+
+
+FILE *
+os_file_create_unique(const char *filename, int filemode)
+{
+ int fd = open(filename, O_CREAT | O_EXCL | O_WRONLY, filemode);
+ if (fd == -1)
+ return NULL;
+ return fdopen(fd, "w");
+}
+
#if defined(__linux__)