K
Keith Thompson
If calling fopen() with "this_is_a_very_long_file_name.txt" invokes
undefined behaviour, all the bets are off.
Yes, they would be, but I don't see anything in the standard that says
fopen() can invoke undefined behavior, as long as both arguments point
to strings and the second argument has one of the specified values.
As long as those conditions are satisfied, fopen() either succeeds and
returns a pointer to the object controlling the stream, or fails and
returns a null pointer.
Yes, but it's on the safe side: any file name of 13 characters or less is
OK for the file system under question. Since this is a QoI issue, the
conformance of the HP-UX implementation is not affected.
Gosh, Dan, I guess you're right. I don't know why I didn't think of
that.
Oh, wait, I did.
Here's what I wrote:
] As for HP-UX defining FILENAME_MAX as 14, I think HP has at least
] committed an off-by-one error. I recall that early Unix systems
] limited file names to 14 characters. FILENAME_MAX "expands to an
] integer constant expression that is the size needed for an array of
] char large enough to hold the longest file name string that the
] implementation guarantees can be opened". An array holding a string
] of length 14 has to be at least 15 characters long. (That doesn't
] make HP-UX's C implementation non-conforming, it just means that they
] (absurdly) choose guarantee that files with 13-character names, but
] not with 14-character names, can be opened.)
You snipped most of the paragraph, including the part where I
explicitly made the point that HP's off-by-one error doesn't affect
the conformance of their implementation. You then made exactly the
same point yourself. Why?
If defining FILENAME_MAX as 14 is conforming, so is defining it as 2,
or even 1 (the latter would imply that the implementation doesn't
guarantee that any non-empty file name can be fopen()ed). Rejecting
all file names longer than FILENAME_MAX-1 will make a program far less
useful on some conforming systems. Allowing arbitrarily long file
names lets the program determine whether a given file name is accepted
by seeing whether fopen() succeeds.