Sujet : Re: Buffer contents well-defined after fgets() reaches EOF ?
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.lang.cDate : 10. Feb 2025, 08:21:11
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <voc9d7$13pam$2@dont-email.me>
References : 1 2 3 4 5 6 7
User-Agent : Pan/0.161 (Chasiv Yar; )
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.
A practical experiment demonstrates that [supposedly] POSIX-obeying
implementations do not write '\0' into the buffer in "immediate
end-of-file" situations:
https://coliru.stacked-crooked.com/a/3e672e6718dd388b
My test program does the same. I would say that settles it.