diff --git a/libc/src/stdio/scanf_core/file_reader.h b/libc/src/stdio/scanf_core/file_reader.h --- a/libc/src/stdio/scanf_core/file_reader.h +++ b/libc/src/stdio/scanf_core/file_reader.h @@ -30,6 +30,7 @@ char get_char(); void unget_char(char c); + bool has_error() { return file->error_unlocked(); } }; } // namespace scanf_core diff --git a/libc/src/stdio/scanf_core/reader.h b/libc/src/stdio/scanf_core/reader.h --- a/libc/src/stdio/scanf_core/reader.h +++ b/libc/src/stdio/scanf_core/reader.h @@ -45,6 +45,8 @@ void ungetc(char c); size_t chars_read() { return cur_chars_read; } + + bool has_error(); }; } // namespace scanf_core diff --git a/libc/src/stdio/scanf_core/reader.cpp b/libc/src/stdio/scanf_core/reader.cpp --- a/libc/src/stdio/scanf_core/reader.cpp +++ b/libc/src/stdio/scanf_core/reader.cpp @@ -33,5 +33,12 @@ } } +bool Reader::has_error() { + if (reader_type == ReaderType::File) { + return file_reader->has_error(); + } + return false; +} + } // namespace scanf_core } // namespace __llvm_libc diff --git a/libc/src/stdio/scanf_core/scanf_main.cpp b/libc/src/stdio/scanf_core/scanf_main.cpp --- a/libc/src/stdio/scanf_core/scanf_main.cpp +++ b/libc/src/stdio/scanf_core/scanf_main.cpp @@ -35,7 +35,7 @@ } } - if (conversions == 0 && ret_val != READ_OK) { + if (conversions == 0 && reader->has_error()) { // This is intended to be converted to EOF in the client call to avoid // including stdio.h in this internal file. return -1;