Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Jan 2002 20:48:46 +1000
From:      Greg Black <gjb@gbch.net>
To:        Foldi Tamas <crow@localhost.hu>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: interesting open() issue 
Message-ID:  <nospam-1011178126.76622@bambi.gbch.net>
In-Reply-To: <20020116105923.A29210@hax0r.hu>  of Wed, 16 Jan 2002 10:59:23 %2B0100
References:  <20020116105923.A29210@hax0r.hu> 

next in thread | previous in thread | raw e-mail | index | archive | help
Foldi Tamas wrote:

| Hello hackers,

Don't send this sort of newbie programmer question to the
hackers list (or to any of the FreeBSD lists).

| 	I tried the following program on Tru64, FreeBSD and linux:
| 
| #include <stdio.h>
| #include <fcntl.h>
| #include <sys/stat.h>
| #include <sys/types.h>
| main() {
|         int fd;
|         fd = open ( "/tmp/foobar", (O_RDWR | O_CREAT),  0020);
|         perror("open");
|         close(fd);
| }
| 
| The program ran successfully, but the created file was different.
| On Linux:
|     -----w----    1 crow     crow            0 Jan 16 10:32 /tmp/foobar
| 
| On Tru64/FreeBSD:
|     ----------    1 crow     users           0 Jan 16 10:30 /tmp/foobar
| 
| I'm not sure what the result supposed to be. Any ideas ?

If you want the exact same results on each system and if you
want the file to have the mode you set, you need to put two
additional system calls *before* the open(2) call:

    unlink("/tmp/foobar");
    umask(0);

If the file exists, the mode in the open() won't affect it and
it will retain whatever it already had, so you need to ensure
that it's not there first.  If your umask setting masks the
group write bit, it won't be set unless you first clear the
umask setting.

Now go and read about Unix programming.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?nospam-1011178126.76622>