Date: Tue, 28 Aug 2001 15:23:39 +1200 From: Jonathan Chen <jonathan.chen@itouch.co.nz> To: FreeBSD <freebsd@XtremeDev.com> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: open() in FreeBSD? Message-ID: <20010828152339.B49541@itouchnz.itouch> In-Reply-To: <20010827210707.G43076-100000@Amber.XtremeDev.com>; from freebsd@XtremeDev.com on Mon, Aug 27, 2001 at 09:13:28PM -0600 References: <20010827210707.G43076-100000@Amber.XtremeDev.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Aug 27, 2001 at 09:13:28PM -0600, FreeBSD wrote:
> Hello, I have the following test program:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <fcntl.h>
>
> int main()
> {
> int fd = open("blah", O_WRONLY|O_CREAT);
> close(fd);
> return EXIT_SUCCESS;
> }
>
> When I compiled this and run it, ls -l blah gives me:
>
> ---------x 1 freebsd freebsd - 0 Aug 27 20:46 blah*
>
> Looking through man 2 umask, the default umask is 022. Yet the file
> created by open() gives me a mask of 001? In the shell I checked the
> umask, and it indeed is at 022. If the default umask is 022, why does
> leaving out the third argument to open() not follow chmod/umask as implied
> by the man 2 open?
The manpage states:
"The flags argument may indicate the file is to be created if it does
not exist (by specifying the O_CREAT flag). In this case open requires
a third argument mode_t mode, and the file is created with mode mode as
described in chmod(2) and modified by the process' umask value (see
umask(2))."
Since you've got the O_CREAT flag set, the open(2) system call will then
inspect the third argument. In your case you've neglected to specify a
3rd argument, so what ever garbage is on the stack will be used instead.
Hope that clears it up for you.
--
Jonathan Chen <jonathan.chen@itouch.co.nz>
----------------------------------------------------------------------
Jesus saves.
Allah forgives.
Cthulu thinks you'd make a nice sandwich.
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010828152339.B49541>
