aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-xml-utils.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2003-01-16 03:43:44 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2003-01-16 03:43:44 +0800
commit19f3fecce6684ec0386f0ed6e50f3aebbbce9d8a (patch)
tree02680cb6ee092fb48e3afd10018aec0034d4b6c0 /e-util/e-xml-utils.c
parentc22f252ffb46424a97c348bcd93b7dced6f2682b (diff)
downloadgsoc2013-evolution-19f3fecce6684ec0386f0ed6e50f3aebbbce9d8a.tar
gsoc2013-evolution-19f3fecce6684ec0386f0ed6e50f3aebbbce9d8a.tar.gz
gsoc2013-evolution-19f3fecce6684ec0386f0ed6e50f3aebbbce9d8a.tar.bz2
gsoc2013-evolution-19f3fecce6684ec0386f0ed6e50f3aebbbce9d8a.tar.lz
gsoc2013-evolution-19f3fecce6684ec0386f0ed6e50f3aebbbce9d8a.tar.xz
gsoc2013-evolution-19f3fecce6684ec0386f0ed6e50f3aebbbce9d8a.tar.zst
gsoc2013-evolution-19f3fecce6684ec0386f0ed6e50f3aebbbce9d8a.zip
Back to the land of the living we shall go.
2003-01-15 Jeffrey Stedfast <fejj@ximian.com> * gal/util/e-xml-utils.c (e_xml_save_file): Back to the land of the living we shall go. svn path=/trunk/; revision=19482
Diffstat (limited to 'e-util/e-xml-utils.c')
-rw-r--r--e-util/e-xml-utils.c67
1 files changed, 63 insertions, 4 deletions
diff --git a/e-util/e-xml-utils.c b/e-util/e-xml-utils.c
index 4bc1b9e7d7..b33fb74ca5 100644
--- a/e-util/e-xml-utils.c
+++ b/e-util/e-xml-utils.c
@@ -26,10 +26,6 @@
#include <config.h>
#endif
-#ifdef HAVE_ALLOCA_H
-#include <alloca.h>
-#endif
-
#include "e-xml-utils.h"
#include <stdio.h>
@@ -441,3 +437,66 @@ e_xml_get_translated_string_prop_by_name (const xmlNode *parent, const xmlChar *
}
+int
+e_xml_save_file (const char *filename, xmlDocPtr doc)
+{
+ char *filesave, *slash, *xmlbuf;
+ size_t n, written = 0;
+ int ret, fd, size;
+ int errnosave;
+ ssize_t w;
+
+ filesave = alloca (strlen (filename) + 5);
+ slash = strrchr (filename, '/');
+ if (slash)
+ sprintf (filesave, "%.*s.#%s", slash - filename + 1, filename, slash + 1);
+ else
+ sprintf (filesave, ".#%s", filename);
+
+ fd = open (filesave, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+ if (fd == -1)
+ return -1;
+
+ xmlDocDumpMemory (doc, (xmlChar **) &xmlbuf, &size);
+ if (size <= 0) {
+ close (fd);
+ unlink (filesave);
+ errno = ENOMEM;
+ return -1;
+ }
+
+ n = (size_t) size;
+ do {
+ do {
+ w = write (fd, xmlbuf + written, n - written);
+ } while (w == -1 && errno == EINTR);
+
+ if (w > 0)
+ written += w;
+ } while (w != -1 && written < n);
+
+ xmlFree (xmlbuf);
+
+ if (written < n || fsync (fd) == -1) {
+ errnosave = errno;
+ close (fd);
+ unlink (filesave);
+ errno = errnosave;
+ return -1;
+ }
+
+ while ((ret = close (fd)) == -1 && errno == EINTR)
+ ;
+
+ if (ret == -1)
+ return -1;
+
+ if (rename (filesave, filename) == -1) {
+ errnosave = errno;
+ unlink (filesave);
+ errno = errnosave;
+ return -1;
+ }
+
+ return 0;
+}