After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 656192 - g_key_file_load_from_file will abort if the specified file is empty
g_key_file_load_from_file will abort if the specified file is empty
Status: RESOLVED DUPLICATE of bug 663432
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-08-09 07:12 UTC by Mike Manilone
Modified: 2012-01-04 05:38 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Mike Manilone 2011-08-09 07:12:34 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.
Comment 1 Matthias Clasen 2012-01-04 05:38:47 UTC

*** This bug has been marked as a duplicate of bug 663432 ***