Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!uw-beaver!teknowledge-vaxc!sri-unix!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.unix.questions Subject: Re: Question about discrepancy of open()'s documentation; BSD vs. SYS V Keywords: open, documentation Message-ID: <991@cresswell.quintus.UUCP> Date: 18 May 88 09:08:56 GMT References: <5068@nsc.nsc.com> Organization: Quintus Computer Systems, Mountain View, CA Lines: 20 Posted: Wed May 18 02:08:56 1988 In article <5068@nsc.nsc.com>, andrew@nsc.nsc.com (Andrew Lue) writes: > According to K&R, the format of the open() function is: > fd = open(name,rwmode); > where rwmode is 0, 1, or 2. > In the BSD documents, the format is > open(path, flags, mode); This is *NOT* a discrepancy between BSD and System V. (K&R 1st edition precedes System V by years and years.) If you look at the SVID, you will find that the open(BA_OS) call is int open(char *path, int oflag, int mode) 0 (== O_RDONLY), 1 (== O_WRONLY), and 2 (== O_RDWR) will work fine. The "mode" argument is a protection mask, just like you'd give to chmod(). It is only heeded if you specify O_CREAT in the flags argument, and the file didn't previously exist. So, to open a file for output, creating it with protection rwxr----- if it didn't previously exist, do fd = open(path, O_WRONLY | O_CREAT, 0640); More briefly, RTFM.