GNOME Bugzilla – Bug 677817
g_key_file_to_data adds extra blank lines in some cases
Last modified: 2012-06-15 22:53:54 UTC
Here is test program: ========= #include <glib.h> #include <assert.h> int main() { GKeyFile *kfini = g_key_file_new(); assert(g_key_file_load_from_file(kfini, "ini_orig", G_KEY_FILE_KEEP_COMMENTS, NULL)); g_key_file_set_integer(kfini, "Group1", "key2", 0); assert(g_key_file_remove_key(kfini, "Group1", "key2", NULL)); gsize len; gchar *data = g_key_file_to_data(kfini, &len, NULL); assert(data != NULL && len != 0); assert(g_file_set_contents("ini_new", data, len, NULL)); g_free(data); g_key_file_free(kfini); return 0; } ========= Here is test ini_orig file: ========= [Group1] key1=value1 [Group2] key1=value1 ========= And after run ./test_program blank line adds at the end of [Group1]: ========= $ diff -u ini_orig init_new --- ini_orig +++ ini_new @@ -2,6 +2,7 @@ [Group1] key1=value1 + [Group2] key1=value1 ========= I found this problem in these applications using GKeyFile: mc after work ending, ini-file '.config/mc/ini', groups '[Midnight-Commander]' and '[Layout]' evince after printing some document, ini-file '.config/evince/print-settings', group '[Print Settings]'