Comment 3 for bug 999718

Revision history for this message
Matt Fischer (mfisch) wrote : Re: what g_open version?

This builds fine on Ubuntu, and so does this simple test code:

#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <glib/gstdio.h>
#include <glib.h>

int main(void)
{
    int fd;
    fd = g_open ("./foo.c", O_RDONLY);
    if (fd >= 0) {
        close(fd);
    }
    fd = g_open ("./foo.c", O_RDONLY, 0);
    if (fd >= 0) {
        close(fd);
    }
    return 0;
}

mfisch@caprica:~/tmp$ gcc foo.c `pkg-config glib-2.0 --cflags --libs` -Wall
mfisch@caprica:~/tmp$

g_open is backed by open, and if you look at the open manpage it says "mode specifies the permissions to use in case a new file is created. This argument must be supplied when O_CREAT is specified in flags; if O_CREAT is not specified, then mode is ignored."

It seems that glib for me anyway is respecting this ignore option, although I cannot make it fail even if I switch the call above to O_CREAT and don't set a 3rd argument.

Are we using the same glib? I am using 2.32.1-0ubuntu2.

Of course we can still specify a mode here so that it doesn't break your build, but I'd like to know why it works fine for me.