diff --git a/libc/src/stdio.cpp b/libc/src/stdio.cpp index e48e2900..d21960ac 100644 --- a/libc/src/stdio.cpp +++ b/libc/src/stdio.cpp @@ -432,7 +432,12 @@ extern "C" { u8 value; ssize_t rc = read_from_buffer(stream, &value, 1); - if (rc <= 0) return EOF; + if (rc < 0) + { + stream->_err = 1; + return EOF; + } + else if (rc == 0) { return EOF; } return value; } diff --git a/libos/src/File.cpp b/libos/src/File.cpp index 4bee3fe1..04557337 100644 --- a/libos/src/File.cpp +++ b/libos/src/File.cpp @@ -149,9 +149,9 @@ namespace os int current; while (true) { - current = fgetc(m_file); + current = TRY(getchar()); - if (current == -1) break; + if (current == EOF) break; TRY(data.try_append((char)current)); @@ -208,7 +208,9 @@ namespace os Result File::getchar() { - return fgetc(m_file); + int rc = fgetc(m_file); + if (rc == EOF && ferror(m_file)) return err(errno); + return rc; } void File::set_close_on_exec()