40 #include <glib/gi18n.h>
41 #include <glib/gstdio.h>
66 gboolean ignore_error,
67 gboolean return_empty_struct,
68 GError **caller_error)
73 g_return_val_if_fail(filename != NULL, NULL);
75 if (!g_file_test(filename, G_FILE_TEST_EXISTS))
78 key_file = g_key_file_new();
82 if (g_key_file_load_from_file(key_file, filename, G_KEY_FILE_NONE, &error))
86 if (!return_empty_struct)
88 g_key_file_free(key_file);
93 g_warning(
"Unable to read file %s: %s\n", filename, error->message);
94 g_propagate_error(caller_error, error);
109 gboolean success = TRUE;
111 g_return_val_if_fail(filename != NULL, FALSE);
112 g_return_val_if_fail(key_file != NULL, FALSE);
114 g_return_val_if_fail(*error == NULL, FALSE);
116 contents = g_key_file_to_data(key_file, NULL, NULL);
117 DEBUG(
"Keyfile data:\n%s", contents);
118 length = strlen(contents);
119 fd = g_open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
124 *error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno),
125 "Cannot open file %s: %s", filename,
130 g_critical(
"Cannot open file %s: %s\n", filename, strerror(errno));
136 written = write(fd, contents, length);
142 *error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno),
143 "Cannot write to file %s: %s", filename,
148 g_critical(
"Cannot write to file %s: %s\n", filename, strerror(errno));
152 else if (written != length)
157 *error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno),
158 "File %s truncated (provided %d, written %d)",
159 filename, length, (
int)written);
163 g_critical(
"File %s truncated (provided %d, written %d)",
164 filename, length, (
int)written);
169 else if (close(fd) == -1)
173 *error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno),
174 "Close failed for file %s: %s", filename,
179 g_warning(
"Close failed for file %s: %s", filename, strerror(errno));
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
#define DEBUG(format, args...)
GKeyFile helper routines.
gboolean gnc_key_file_save_to_file(const gchar *filename, GKeyFile *key_file, GError **error)
GKeyFile * gnc_key_file_load_from_file(const gchar *filename, gboolean ignore_error, gboolean return_empty_struct, GError **caller_error)
const gchar * QofLogModule