From bd08664f05507c7bf1b77657a9869afb168d93a6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 1 Aug 2019 10:49:44 +0200 Subject: [PATCH] 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. --- Libraries/LibC/stdio.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Libraries/LibC/stdio.cpp b/Libraries/LibC/stdio.cpp index 05f60495ac..713853caaf 100644 --- a/Libraries/LibC/stdio.cpp +++ b/Libraries/LibC/stdio.cpp @@ -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)