diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2020-12-30 18:39:43 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2020-12-30 18:39:43 (GMT) |
commit | 93e9ab125bced1374c7d4a03e5bd11a0dc1b2968 (patch) | |
tree | 54f82bdfe8e23530a291128dea01911a2f214115 | |
parent | a6a88792bc866d8a1d7cabd50a93374da5dd1e7a (diff) |
Skipped empty XML document storage.
-rw-r--r-- | src/common/xml.c | 27 |
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; } |