LibC: In fgetc(), fread() will never return < 0.

Furthermore, fread() has already handled EOF, so there's no need to do
it again. If we read a character, return it, otherwise return EOF.
Note that EOF means "EOF or error" here.
This commit is contained in:
Andreas Kling 2019-08-01 10:49:44 +02:00
parent caeb4b7a7e
commit bd08664f05
Notes: sideshowbarker 2024-07-19 12:57:59 +09:00

View File

@ -129,12 +129,9 @@ int fgetc(FILE* stream)
assert(stream);
char ch;
size_t nread = fread(&ch, sizeof(char), 1, stream);
if (nread <= 0) {
stream->eof = nread == 0;
stream->error = errno;
return EOF;
}
return ch;
if (nread == 1)
return ch;
return EOF;
}
int getc(FILE* stream)