summaryrefslogtreecommitdiff
path: root/Libraries/LibC/stdio.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-08-01 10:49:44 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-08-01 10:50:51 +0200
commitbd08664f05507c7bf1b77657a9869afb168d93a6 (patch)
tree59867347e65b80b7b9bb5e0048b5943cd5e909e6 /Libraries/LibC/stdio.cpp
parentcaeb4b7a7efbd1b6446ea21c48e079557ac5d45a (diff)
downloadserenity-bd08664f05507c7bf1b77657a9869afb168d93a6.zip
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.
Diffstat (limited to 'Libraries/LibC/stdio.cpp')
-rw-r--r--Libraries/LibC/stdio.cpp9
1 files 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)