Dik T. Winter wrote, On 04/02/07 03:08:
How would you open a directory on a system that does not know about
directories?
The same as trying to open a file that does not exist, it fails. The
standard *could* have provided a method for getting a list of files
where the "file list open" function took a name that the implementation
treated as it wished with no guarantee that the "file list open"
function would succeed (just as fopen can fail) and no guarantee that
you can open the files that are listed. The standard committee choose
not to do this, but they could have. Note that I have not specified that
the list if files is a directory, nor have I specified that you must be
able to get a list of files.
Or should it open the resource fork or the data fork? Or what if some
of the files are fixed size records (of different sizes) and others are
Z-type records?
You stated it quite clear "unix utilities". You are not talking about
general utilities but about OS specific utilities. It is obvious that
when part of the specification is OS specific, that it can not be
written in standard C.
The statement "unix utilities" was because they are utilities that are
traditionally provided on Unix like systems, not because they rely on
unix. Unless you think that reading a file (name specified on the
command line) and sending the output to stdout relies on some Unix
specifics (if so what), or reading stdin and sending the output to both
a file (named on the command line) and stdout depends on some unix
specific call, or...
There are a number of "unix utilities" that do not rely on anything that
is specific to Unix even though they are provided with Unix type
systems. The ones I am thinking of are specifically designed to operate
on text files so should open the file in text mode and if it is not a
text file the user gets what s/he deserves.
<snip>
I would say open as text mode. However, you could always add a switch to
specify whether the file(s) should be opened in text or binary mode and
it would be just as (or more) useful.