From owner-freebsd-questions Mon Aug 27 20:24: 1 2001 Delivered-To: freebsd-questions@freebsd.org Received: from itouch.co.nz (itouch.co.nz [203.99.66.188]) by hub.freebsd.org (Postfix) with ESMTP id 724E737B401 for ; Mon, 27 Aug 2001 20:23:56 -0700 (PDT) (envelope-from jonc@itouch.co.nz) Received: (from jonc@localhost) by itouch.co.nz (8.11.3/8.11.1) id f7S3Nd350266; Tue, 28 Aug 2001 15:23:39 +1200 (NZST) (envelope-from jonc) Date: Tue, 28 Aug 2001 15:23:39 +1200 From: Jonathan Chen To: FreeBSD Cc: freebsd-questions@FreeBSD.ORG Subject: Re: open() in FreeBSD? Message-ID: <20010828152339.B49541@itouchnz.itouch> 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? 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 ---------------------------------------------------------------------- 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