From: solar Date: Mon, 19 Jul 2010 05:19:04 +0000 (+0000) Subject: scanf() returns -1 on early input error. X-Git-Tag: v0.5~58 X-Git-Url: https://pd.if.org/git/?p=pdclib;a=commitdiff_plain;h=00379f785fe102b41c75761d4c1f2a1dbb8d1fde scanf() returns -1 on early input error. --- diff --git a/functions/stdio/vfscanf.c b/functions/stdio/vfscanf.c index 8f121e9..e1c8b4b 100644 --- a/functions/stdio/vfscanf.c +++ b/functions/stdio/vfscanf.c @@ -53,10 +53,14 @@ int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict forma if ( ( ( c = getc( stream ) ) != *format ) || feof( stream ) ) /* TODO: Check EOF status directly */ { /* Matching error */ - if ( ! feof( stream ) ) /* TODO: Check EOF status directly */ + if ( ! feof( stream ) && ! ferror( stream ) ) /* TODO: Check EOF status directly */ { ungetc( c, stream ); } + else if ( status.n == 0 ) + { + return EOF; + } return status.n; } else