Question about discrepancy of open()'s documentation

Doug Gwyn gwyn at brl-smoke.ARPA
Thu May 19 04:29:36 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);

It used to be like that.

> In the BSD documents, the format is
> open(path, flags, mode);

This was changed when USG assimilated creat() into open();
the extra argument is needed to specify the initial protection mode.

By the way, you're using "format" in a very loose way; see comments
below about imprecision in interface specification.

> With my experiments, I can get the first format to work.  When is
> the second format applicable?  When I invoke the C compiler, I don't
> pass any flags.

You mean you don't pass any `mode' argument.
This happens to work, by accident, on most existing systems
(which is why the USG change was able to get adopted).
To play safe, I always supply all three arguments.

The correct portable declaration according to draft IEEE Std 1003.1 is
	int open(char *path, int oflag, ...);
i.e. a variable-argument function linkage.  (The P1003 Working Group
had to choose some way to fix the technical error, and this is the
one they decided on.)  Actually in Draft 12 they botched it by trying
to mix old- and new-style function declaration syntax, or more
precisely by not having a clear idea about what the various C-like
"declarations" are really meant to signify.  (To be fair, this seems
to be a long-standing UNIX documentation tradition.)  The above is
my straightened-out interpretation of what was intended.  You should
never have to declare the open() function yourself, anyway; just
	#include <fcntl.h>
(I think the revised Draft 12.whatever also shows <sys/types.h> and
<sys/stat.h>; ignore that.)



More information about the Comp.unix.questions mailing list