From 71eabe9f8c8c6a31f26cd1a02d1f49612bc46f38 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Tue, 6 Aug 2002 20:31:40 +0000 Subject: #include for memset 2002-08-06 Jeffrey Stedfast * e-cell-progress.c: #include for memset * e-table.c (e_table_save_specification): Updated to use e_xml_save_file() instead of xmlSaveFile(). Also fixed to save to a tmp file first. * e-table-specification.c (e_table_specification_save_to_file): Same as above. * e-table-state.c (e_table_state_save_to_file): Same here. * e-tree-table-adapter.c (e_tree_table_adapter_save_expanded_state): And here too. svn path=/trunk/; revision=17717 --- widgets/table/e-cell-progress.c | 6 ++++++ widgets/table/e-table-specification.c | 37 +++++++++++++++++++++++++++++++---- widgets/table/e-table-state.c | 35 +++++++++++++++++++++++++++++---- widgets/table/e-table.c | 32 ++++++++++++++++++++++++------ widgets/table/e-tree-table-adapter.c | 36 +++++++++++++++++++++++++++------- 5 files changed, 125 insertions(+), 21 deletions(-) diff --git a/widgets/table/e-cell-progress.c b/widgets/table/e-cell-progress.c index 41edac7ef3..d38adb5082 100644 --- a/widgets/table/e-cell-progress.c +++ b/widgets/table/e-cell-progress.c @@ -26,7 +26,13 @@ * 02111-1307, USA. */ + +#ifdef HAVE_CONFIG_H #include +#endif + +#include + #include #include #include diff --git a/widgets/table/e-table-specification.c b/widgets/table/e-table-specification.c index 4c04d78c80..92f8b42921 100644 --- a/widgets/table/e-table-specification.c +++ b/widgets/table/e-table-specification.c @@ -21,12 +21,18 @@ * 02111-1307, USA. */ +#ifdef HAVE_CONFIG_H #include +#endif #include "e-table-specification.h" +#include #include #include +#include +#include + #include #include #include @@ -272,21 +278,44 @@ e_table_specification_load_from_node (ETableSpecification *specification, * * This routine stores the @specification into @filename. * - * Returns: the number of bytes written or -1 on error. + * Returns: 0 on success or -1 on error. */ int e_table_specification_save_to_file (ETableSpecification *specification, const char *filename) { + char *tmp, *slash; xmlDoc *doc; - + int ret; + g_return_val_if_fail (specification != NULL, -1); g_return_val_if_fail (filename != NULL, -1); g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (specification), -1); - doc = xmlNewDoc ("1.0"); + if ((doc = xmlNewDoc ("1.0")) == NULL) { + errno = ENOMEM; + return -1; + } + xmlDocSetRootElement (doc, e_table_specification_save_to_node (specification, doc)); - return xmlSaveFile (filename, doc); + + tmp = alloca (strlen (filename) + 5); + slash = strrchr (filename, '/'); + if (slash) + sprintf (tmp, "%.*s.#%s", slash - filename + 1, filename, slash + 1); + else + sprintf (tmp, ".#%s", filename); + + ret = e_xml_save_file (tmp, doc); + if (ret != -1) + ret = rename (tmp, filename); + + if (ret == -1) + unlink (tmp); + + xmlFreeDoc (doc); + + return ret; } /** diff --git a/widgets/table/e-table-state.c b/widgets/table/e-table-state.c index a0d746bf36..59a05f6738 100644 --- a/widgets/table/e-table-state.c +++ b/widgets/table/e-table-state.c @@ -21,9 +21,17 @@ * 02111-1307, USA. */ + +#ifdef HAVE_CONFIG_H #include +#endif + +#include #include #include +#include +#include + #include #include #include @@ -179,11 +187,30 @@ void e_table_state_save_to_file (ETableState *state, const char *filename) { + char *tmp, *slash; xmlDoc *doc; - doc = xmlNewDoc("1.0"); - xmlDocSetRootElement(doc, e_table_state_save_to_node(state, NULL)); - xmlSaveFile(filename, doc); - xmlFreeDoc(doc); + int ret; + + if ((doc = xmlNewDoc ("1.0")) == NULL) + return; + + xmlDocSetRootElement (doc, e_table_state_save_to_node (state, NULL)); + + tmp = alloca (strlen (filename) + 5); + slash = strrchr (filename, '/'); + if (slash) + sprintf (tmp, "%.*s.#%s", slash - filename + 1, filename, slash + 1); + else + sprintf (tmp, ".#%s", filename); + + ret = e_xml_save_file (tmp, doc); + if (ret != -1) + ret = rename (tmp, filename); + + if (ret == -1) + unlink (tmp); + + xmlFreeDoc (doc); } char * diff --git a/widgets/table/e-table.c b/widgets/table/e-table.c index 13873f12b0..2fba247dab 100644 --- a/widgets/table/e-table.c +++ b/widgets/table/e-table.c @@ -22,11 +22,16 @@ * 02111-1307, USA. */ + +#ifdef HAVE_CONFIG_H #include -#include +#endif + #include +#include #include -#include +#include + #include #include #include @@ -1785,15 +1790,30 @@ e_table_set_specification (ETable *e_table, const char *spec) } void -e_table_save_specification (ETable *e_table, gchar *filename) +e_table_save_specification (ETable *e_table, const char *filename) { xmlDoc *doc = et_build_tree (e_table); - + char *tmp, *slash; + int ret; + g_return_if_fail(e_table != NULL); g_return_if_fail(E_IS_TABLE(e_table)); g_return_if_fail(filename != NULL); - - xmlSaveFile (filename, doc); + + tmp = alloca (strlen (filename) + 5); + slash = strrchr (filename, '/'); + if (slash) + sprintf (tmp, "%.*s.#%s", slash - filename + 1, filename, slash + 1); + else + sprintf (tmp, ".#%s", filename); + + ret = e_xml_save_file (tmp, doc); + if (ret != -1) + ret = rename (tmp, filename); + + if (ret == -1) + unlink (tmp); + xmlFreeDoc (doc); } diff --git a/widgets/table/e-tree-table-adapter.c b/widgets/table/e-tree-table-adapter.c index 20f41e6ebc..552b15ddf6 100644 --- a/widgets/table/e-tree-table-adapter.c +++ b/widgets/table/e-tree-table-adapter.c @@ -22,9 +22,17 @@ * 02111-1307, USA. */ + +#ifdef HAVE_CONFIG_H #include +#endif + +#include #include #include +#include +#include + #include #include #include @@ -931,11 +939,13 @@ save_expanded_state_func (gpointer keyp, gpointer value, gpointer data) void e_tree_table_adapter_save_expanded_state (ETreeTableAdapter *etta, const char *filename) { - xmlDoc *doc; - xmlNode *root; ETreeTableAdapterPriv *priv; + char *tmp, *slash; TreeAndRoot tar; - + xmlDocPtr doc; + xmlNode *root; + int ret; + g_return_if_fail(etta != NULL); priv = etta->priv; @@ -951,13 +961,25 @@ e_tree_table_adapter_save_expanded_state (ETreeTableAdapter *etta, const char *f tar.root = root; tar.tree = etta->priv->source; - + g_hash_table_foreach (priv->attributes, save_expanded_state_func, &tar); - - xmlSaveFile (filename, doc); - + + tmp = alloca (strlen (filename) + 5); + slash = strrchr (filename, '/'); + if (slash) + sprintf (tmp, "%.*s.#%s", slash - filename + 1, filename, slash + 1); + else + sprintf (tmp, ".#%s", filename); + + ret = e_xml_save_file (tmp, doc); + if (ret != -1) + ret = rename (tmp, filename); + + if (ret == -1) + unlink (tmp); + xmlFreeDoc (doc); } -- cgit v1.2.3