john said:
I think you are being deliberately obtuse here.
It looks like you just didn't express your proposal clearly enough.
A lot of smart people here drew the same conclusion I did about
what you're proposing.
I am proposing no such thing. What I am proposing is that passing a
string to fopen() that is not in 8.3 format should invoke an undefined
behavior (actually, implementation defined behavior would be even better).
Ok, here's what you wrote upthread (emphasis added):
My question is: as DOS is a common target for C, wouldn't it be
better if fopen() *only allowed* strings of length <11 and in
the format 8.3 for maximum compatability, and had an *undefined
behavior* if it was given a string in another format?
(And I think you meant "<=12" rather than "<11"; the '.' is part of the
file name.)
A Linux implementation would be free to choose to open any filename you
threw at it. A DOS implementation obviously couldn't do this in the
absence of a LFN support layer.
Yes, implementation-defined behavior makes much more sense than the
undefined behavior you originally proposed.
And how exactly does your proposal differ from the current situation?
C99 7.19.5.3p2:
The fopen function opens the file whose name is the string
pointed to by filename, and associates a stream with it.
and p8:
The fopen function returns a pointer to the object controlling
the stream. If the open operation fails, fopen returns a
null pointer.
And C99 7.19.3p8:
Functions that open additional (nontemporary) files require
a file name, which is a string. The rules for composing
valid file names are implementation-defined.
So the C standard already says that valid file names are
implementation-defined. As far as I can tell, the only thing your
proposal would change is to give some special status to names that
fit within the MS-DOS 8.3 limits.
Oh, wait, it would also make the behavior of fopen() when given a
non-8.3 file name implementation-defined, rather than (as in the
current standard) requiring it either to succeed or to return a
null pointer to indicate failure.
Since there's nothing particularly special about MS-DOS with respect
to the C standard (some systems impose looser restrictions on file
names, some impose tighter ones), I'll say again that your proposal,
as you've re-explained it, is either already covered by the standard
or a bad idea.
Under your proposal, if an OS only supports 7.3 file names, or
doesn't permit '.' in file names, would a C implementation
on that system be required to support DOS-style 8.3 file names?
What would be the benefit of such a requirement?