Commit 5d7a7df8 authored by Allison Karlitskaya's avatar Allison Karlitskaya

Add g_key_file_save_to_file()

To write a keyfile to disk.

https://bugzilla.gnome.org/show_bug.cgi?id=309224
parent 5a269e5a
......@@ -1822,6 +1822,7 @@ g_key_file_load_from_data
g_key_file_load_from_data_dirs
g_key_file_load_from_dirs
g_key_file_to_data
g_key_file_save_to_file
g_key_file_get_start_group
g_key_file_get_groups
g_key_file_get_keys
......
......@@ -4372,3 +4372,41 @@ g_key_file_parse_comment_as_value (GKeyFile *key_file,
return g_string_free (string, FALSE);
}
/**
* g_key_file_save_to_file:
* @key_file: a #GKeyFile
* @filename: the name of the file to write to
* @error: a pointer to a %NULL #GError, or %NULL
*
* Writes the contents of @key_file to @filename using
* g_file_set_contents().
*
* This function can fail for any of the reasons that
* g_file_set_contents() may fail.
*
* Returns: %TRUE if successful, else %FALSE with @error set
*
* Since: 2.40
*/
gboolean
g_key_file_save_to_file (GKeyFile *key_file,
const gchar *filename,
GError **error)
{
gchar *contents;
gboolean success;
gsize length;
g_return_val_if_fail (key_file != NULL, FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
contents = g_key_file_to_data (key_file, &length, NULL);
g_assert (contents != NULL);
success = g_file_set_contents (filename, contents, length, error);
g_free (contents);
return success;
}
......@@ -94,6 +94,10 @@ GLIB_AVAILABLE_IN_ALL
gchar *g_key_file_to_data (GKeyFile *key_file,
gsize *length,
GError **error) G_GNUC_MALLOC;
GLIB_AVAILABLE_IN_2_40
gboolean g_key_file_save_to_file (GKeyFile *key_file,
const gchar *filename,
GError **error);
GLIB_AVAILABLE_IN_ALL
gchar *g_key_file_get_start_group (GKeyFile *key_file) G_GNUC_MALLOC;
GLIB_AVAILABLE_IN_ALL
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment