Add g_key_file_save_to_file()

To write a keyfile to disk.

https://bugzilla.gnome.org/show_bug.cgi?id=309224
This commit is contained in:
Ryan Lortie 2013-10-03 12:39:53 -04:00
parent 5a269e5a90
commit 5d7a7df867
3 changed files with 43 additions and 0 deletions

View File

@ -1822,6 +1822,7 @@ g_key_file_load_from_data
g_key_file_load_from_data_dirs g_key_file_load_from_data_dirs
g_key_file_load_from_dirs g_key_file_load_from_dirs
g_key_file_to_data g_key_file_to_data
g_key_file_save_to_file
g_key_file_get_start_group g_key_file_get_start_group
g_key_file_get_groups g_key_file_get_groups
g_key_file_get_keys g_key_file_get_keys

View File

@ -4372,3 +4372,41 @@ g_key_file_parse_comment_as_value (GKeyFile *key_file,
return g_string_free (string, FALSE); 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;
}

View File

@ -94,6 +94,10 @@ GLIB_AVAILABLE_IN_ALL
gchar *g_key_file_to_data (GKeyFile *key_file, gchar *g_key_file_to_data (GKeyFile *key_file,
gsize *length, gsize *length,
GError **error) G_GNUC_MALLOC; 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 GLIB_AVAILABLE_IN_ALL
gchar *g_key_file_get_start_group (GKeyFile *key_file) G_GNUC_MALLOC; gchar *g_key_file_get_start_group (GKeyFile *key_file) G_GNUC_MALLOC;
GLIB_AVAILABLE_IN_ALL GLIB_AVAILABLE_IN_ALL