creates a .dav dir if it doesn't exist

Mon, 12 Aug 2013 15:58:30 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 12 Aug 2013 15:58:30 +0200
changeset 8
4503498deb22
parent 7
d9bdd5a22c1d
child 9
6aec77cfa95b

creates a .dav dir if it doesn't exist

dav/config.c file | annotate | diff | comparison | revisions
dav/main.c file | annotate | diff | comparison | revisions
--- 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);
--- a/dav/main.c	Mon Aug 12 15:34:40 2013 +0200
+++ b/dav/main.c	Mon Aug 12 15:58:30 2013 +0200
@@ -47,7 +47,7 @@
 }
 
 int main(int argc, char **argv) {
-   xmlGenericErrorFunc fnc = xmlerrorfnc;
+    xmlGenericErrorFunc fnc = xmlerrorfnc;
     initGenericErrorDefaultFunc(&fnc);
     load_config();
     

mercurial