From owner-freebsd-questions Mon Aug 27 20:19:50 2001 Delivered-To: freebsd-questions@freebsd.org Received: from topaz.mdcc.cx (topaz.mdcc.cx [212.204.230.141]) by hub.freebsd.org (Postfix) with ESMTP id B672137B401 for ; Mon, 27 Aug 2001 20:19:45 -0700 (PDT) (envelope-from edwin@mavetju.org) Received: from k7.mavetju.org (topaz.mdcc.cx [212.204.230.141]) by topaz.mdcc.cx (Postfix) with ESMTP id BA5542B68D; Tue, 28 Aug 2001 05:19:41 +0200 (CEST) Received: by k7.mavetju.org (Postfix, from userid 1001) id 635AA3AC; Tue, 28 Aug 2001 13:19:33 +1000 (EST) Date: Tue, 28 Aug 2001 13:19:33 +1000 From: Edwin Groothuis To: FreeBSD Cc: freebsd-questions@FreeBSD.ORG Subject: Re: open() in FreeBSD? Message-ID: <20010828131933.G29422@k7.mavetju.org> Mail-Followup-To: Edwin Groothuis , FreeBSD , freebsd-questions@FreeBSD.ORG References: <20010827210707.G43076-100000@Amber.XtremeDev.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010827210707.G43076-100000@Amber.XtremeDev.com>; from freebsd@XtremeDev.com on Mon, Aug 27, 2001 at 09:13:28PM -0600 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Mon, Aug 27, 2001 at 09:13:28PM -0600, FreeBSD wrote: > Hello, I have the following test program: > > #include > #include > #include > > 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