Am Sat, 18 Jun 2022 14:59:24 +0300
schrieb Eero Tamminen <oak@xxxxxxxxxxxxxx>:
Manual page says:
-----------------
RETURN VALUE
fgetc(), getc(), and getchar() return the character read as an
unsigned
char cast to an int or EOF on end of file *or error*.
Hmm, interesting, I think you read the man page differently than I did.
I interpreted it that way:
(unsigned character) OR (EOF if (end of of file or error))
while you read it that way:
(unsigned character) OR (EOF if end of file) OR (error)
It's ambiguous in the man-page, indeed.
The Posix version (man 3p fgetc) of the man page is more precise:
Upon successful completion, fgetc() shall return the next byte from the in‐
put stream pointed to by stream. If the end-of-file indicator for the
stream is set, or if the stream is at end-of-file, the end-of-file indicator
for the stream shall be set and fgetc() shall return EOF. If a read error
occurs, the error indicator for the stream shall be set, fgetc() shall re‐
turn EOF, and shall set errno to indicate the error.
Anyway, since EOF is guaranteed to be negative, it shouldn't
really matter much in this case, so never mind, let's just
leave the code as it is.