summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/xml.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/common/xml.c b/src/common/xml.c
index 82bb3ac..90c86cd 100644
--- a/src/common/xml.c
+++ b/src/common/xml.c
@@ -31,10 +31,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include "cpp.h"
#include "extstr.h"
+#include "pathname.h"
#ifdef DEBUG
@@ -128,11 +130,32 @@ bool load_xml_from_memory(const char *content, size_t length, xmlDocPtr *xdoc, x
bool save_xml_file(xmlDocPtr xdoc, const char *filename)
{
+ bool result; /* Bilan à retourner */
int ret; /* Bilan de l'appel */
- ret = xmlSaveFormatFileEnc(filename, xdoc, "UTF-8", 1);
+ /**
+ * Le parti est pris de ne pas enregistrer de document vide !
+ */
+
+ if (xmlDocGetRootElement(xdoc) == NULL)
+ {
+ ret = unlink(filename);
+ result = (ret == 0);
+ }
+
+ else
+ {
+ result = mkpath(filename);
+ if (!result) goto exit;
- return (ret != -1);
+ ret = xmlSaveFormatFileEnc(filename, xdoc, "UTF-8", 1);
+ result = (ret != -1);
+
+ }
+
+ exit:
+
+ return result;
}