Maybe there should be a new flag to open(2)

Dave Yost day at kovacs.UUCP
Mon Oct 14 13:04:06 AEST 1985


Say a program wants to open a file and read it.
Say this `file' is really a directory.  The
program reads it, finds the file contains what it
considers garbage, and tells the hapless user
that the file doesn't make sense.  A more useful
error message would tell the user that the object
was a directory, not a file.

Now what is a program to do?  Always do an fstat
on a file and see what it is whenever it finds
nonsense?  Ha!

What if:

    If the O_FILE_TYPE flag to open(2) is set, the
next argument is a bitmask of the allowed file
types that the file may be.  If it is not one of
these types, the open will fail.  The bits in
the bitmask are numbered starting with the least
significant as 0, each bit corresponding to a
value in the S_IFMT field of the st_mode word
(taken as if it were declared as a bit field).

Programs could easily be upgraded to insist on
files when they want files, opendir(3) could
insist that what it is opening is a directory, etc.

--dave yost



More information about the Comp.unix.wizards mailing list