From: solar Date: Fri, 16 Jul 2010 06:13:35 +0000 (+0000) Subject: Fixed EOF handling. X-Git-Tag: v0.5~63 X-Git-Url: https://pd.if.org/git/?p=pdclib;a=commitdiff_plain;h=3fe0b3636381ca114b4b664af4062708d5cddf26 Fixed EOF handling. --- diff --git a/functions/stdio/vfscanf.c b/functions/stdio/vfscanf.c index 99a752f..8f121e9 100644 --- a/functions/stdio/vfscanf.c +++ b/functions/stdio/vfscanf.c @@ -42,7 +42,7 @@ int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict forma { ++status.i; } - if ( c != EOF ) + if ( ! feof( stream ) ) /* TODO: Check EOF status directly */ { ungetc( c, stream ); } @@ -50,10 +50,13 @@ int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict forma else { /* Non-whitespace char in format string: Match verbatim */ - if ( ( c = getc( stream ) ) != *format ) + if ( ( ( c = getc( stream ) ) != *format ) || feof( stream ) ) /* TODO: Check EOF status directly */ { /* Matching error */ - ungetc( c, stream ); + if ( ! feof( stream ) ) /* TODO: Check EOF status directly */ + { + ungetc( c, stream ); + } return status.n; } else