Question about discrepancy of open()'s documentation; BSD vs. SYS V
Richard A. O'Keefe
ok at quintus.UUCP
Wed May 18 19:08:56 AEST 1988
In article <5068 at nsc.nsc.com>, andrew at 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.
More information about the Comp.unix.questions
mailing list