creates an empty configuration file if needed

Mon, 12 Aug 2013 14:55:31 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 12 Aug 2013 14:55:31 +0200
changeset 6
9c64d2a3d101
parent 5
88625853ae74
child 7
d9bdd5a22c1d

creates an empty configuration file if needed

dav/config.c file | annotate | diff | comparison | revisions
--- a/dav/config.c	Mon Aug 12 14:40:19 2013 +0200
+++ b/dav/config.c	Mon Aug 12 14:55:31 2013 +0200
@@ -46,6 +46,15 @@
     
     char *file = util_concat_path(getenv("HOME"), ".dav/config.xml");
     xmlDoc *doc = xmlReadFile(file, NULL, 0);
+    if(!doc) {
+        doc = xmlNewDoc(BAD_CAST "1.0");
+        xmlNode *root = xmlNewNode(NULL, BAD_CAST "configuration");
+        xmlDocSetRootElement(doc, root);
+        xmlSaveFormatFileEnc(file, doc, "UTF-8", 1);
+        xmlFreeDoc(doc);
+        free(file);
+        return;
+    }
     free(file);
     
     xmlNode *xml_root = xmlDocGetRootElement(doc);

mercurial