GNOME Bugzilla – Bug 656192
g_key_file_load_from_file will abort if the specified file is empty
Last modified: 2012-01-04 05:38:47 UTC
====================== if (!g_key_file_load_from_file (config, CFG_KEY_FILE, G_KEY_FILE_NONE, &err)) { g_error (_("Couldn't load configurations file!")); exit (EXIT_FAILURE); } ====================== normally this code will read & parse the key file. but if the file is empty then it will return an error. So I must write the workaround: ====================== int fd = open (CFG_KEY_FILE, O_RDWR | O_CREAT); if (!fd) { g_error (_("Couldn't create key file: %s"), strerror (errno)); exit (EXIT_FAILURE); } struct stat buf; fstat (fd, &buf); if (buf.st_size == 0) { lseek (fd, 0L, SEEK_SET); write (fd, "#\n", 2); } close (fd); ====================== But I think, the function, g_key_file_load_from_file() should not return an error if the file is empty.
*** This bug has been marked as a duplicate of bug 663432 ***