dav/config.c

changeset 8
4503498deb22
parent 7
d9bdd5a22c1d
child 9
6aec77cfa95b
--- a/dav/config.c	Mon Aug 12 15:34:40 2013 +0200
+++ b/dav/config.c	Mon Aug 12 15:58:30 2013 +0200
@@ -29,7 +29,10 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <ucx/map.h>
+#include <errno.h>
 #include <libxml/tree.h>
 
 #include "config.h"
@@ -40,9 +43,24 @@
 static UcxMap *repos;
 static UcxMap *keys;
 
+int check_config_dir() {
+    char *file = util_concat_path(getenv("HOME"), ".dav");
+    int ret = 0;
+    if(mkdir(file, S_IRWXU)) {
+        if(errno != EEXIST) {
+            ret = 1;
+        }
+    }
+    free(file);
+    return ret;
+}
+
 void load_config() {
     repos = ucx_map_new(16);
     keys = ucx_map_new(16);
+    if(check_config_dir()) {
+        return;
+    }
     
     char *file = util_concat_path(getenv("HOME"), ".dav/config.xml");
     xmlDoc *doc = xmlReadFile(file, NULL, 0);

mercurial