Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Aug 2001 13:19:33 +1000
From:      Edwin Groothuis <edwin@mavetju.org>
To:        FreeBSD <freebsd@XtremeDev.com>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: open() in FreeBSD?
Message-ID:  <20010828131933.G29422@k7.mavetju.org>
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?
> 
> "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))." - man 2 open

You didn't quote everything:

     The file name specified by path is opened for reading and/or writing as
     specified by the argument flags and the file descriptor returned to the
|    calling process.  The flags argument may indicate the file is to be cre-
|    ated 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)).

So, if you use O_CREAT, you *have to* supply the third argument!
Otherwise you're not playing according to the rules and you will
be punished for it. Like a 001 :-)

Edwin

-- 
Edwin Groothuis   |              Personal website: http://www.MavEtJu.org
edwin@mavetju.org |           Interested in MUDs? Visit Fatal Dimensions:
------------------+                       http://www.FatalDimensions.org/

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?20010828131933.G29422>