summaryrefslogtreecommitdiffstats
path: root/src/server/helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/helper.c')
-rw-r--r--src/server/helper.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/server/helper.c b/src/server/helper.c
index c86fcb6..e5f520a 100644
--- a/src/server/helper.c
+++ b/src/server/helper.c
@@ -3,6 +3,7 @@
#include <string.h>
#include <stdlib.h>
#include <glib/gmacros.h>
+#include <fcntl.h>
#include "../config.h"
/**
@@ -167,3 +168,28 @@ void remove_trailing_slash(char *string)
while (ptr >= string && *ptr == '/')
*ptr-- = '\0';
}
+
+int file_exists(char *file)
+{
+ int fd = open(file, O_RDONLY);
+ if (fd < 0)
+ return FALSE;
+ close(fd);
+ return TRUE;
+}
+
+int file_writable(char *file)
+{
+ int fd = open(file, O_WRONLY);
+ if (fd >= 0)
+ {
+ close(fd);
+ return TRUE;
+ }
+ fd = open(file, O_WRONLY | O_CREAT, 0600);
+ if (fd < 0)
+ return FALSE;
+ close(fd);
+ unlink(file);
+ return TRUE;
+}