Sujet : Re: Buffer contents well-defined after fgets() reaches EOF ?
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.cDate : 10. Feb 2025, 19:58:05
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vodi7t$1b6at$1@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : Mozilla Thunderbird
On 2/10/25 02:21, Lawrence D'Oliveiro wrote:
On Sun, 9 Feb 2025 20:11:22 -0800, Andrey Tarasevich wrote:
This manpage, for one example, is in full agreement with the standard
>
https://www.man7.org/linux/man-pages/man3/fgets.3p.html
Notice these two sentences would seem to contradict one another:
A null byte shall be written immediately after the last byte read
into the array. If the end-of-file condition is encountered before
any bytes are read, the contents of the array pointed to by s
shall not be changed.
Note: this wording is almost identical to relevant wording in the
current C standard:
"A null character is written immediately after the last character read
into the array." (7.23.7p2).
"If end-of-file is encountered and no characters have been read into the
array, the contents of the array remain unchanged and a null pointer is
returned." (7.23.7p3)
I don't see the contradiction. If "no characters are read into the
array", there is no such thing as "the last byte read into the array",
so a null byte has no location where it should be written. Therefore,
there's no reason for changing the contents of the array.