]> pd.if.org Git - pdclib/commitdiff
Fixed EOF handling.
authorsolar <unknown>
Fri, 16 Jul 2010 06:13:35 +0000 (06:13 +0000)
committersolar <unknown>
Fri, 16 Jul 2010 06:13:35 +0000 (06:13 +0000)
functions/stdio/vfscanf.c

index 99a752ff2db0258fc8ccc67d47faae2162f3e5ac..8f121e95e4a73cac03d000cf6a96132e2163e5ab 100644 (file)
@@ -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