X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdio%2Fvfscanf.c;h=a19f18ef13e6fc9233572dd735da66d419ceb4be;hb=d865c4403fc91d1f1ac95ba76febcee9f429bb97;hp=99a752ff2db0258fc8ccc67d47faae2162f3e5ac;hpb=f56f5d756f412e9c7058e2af4e36bc1de21dd642;p=pdclib diff --git a/functions/stdio/vfscanf.c b/functions/stdio/vfscanf.c index 99a752f..a19f18e 100644 --- a/functions/stdio/vfscanf.c +++ b/functions/stdio/vfscanf.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /* vfscanf( FILE *, const char *, va_list ) This file is part of the Public Domain C Library (PDCLib). @@ -42,7 +40,7 @@ int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict forma { ++status.i; } - if ( c != EOF ) + if ( ! feof( stream ) ) { ungetc( c, stream ); } @@ -50,10 +48,17 @@ 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 ) ) { /* Matching error */ - ungetc( c, stream ); + if ( ! feof( stream ) && ! ferror( stream ) ) + { + ungetc( c, stream ); + } + else if ( status.n == 0 ) + { + return EOF; + } return status.n; } else @@ -81,11 +86,12 @@ int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict forma #endif #ifdef TEST -#include <_PDCLIB_test.h> +#define _PDCLIB_FILEID "stdio/vfscanf.c" +#define _PDCLIB_FILEIO -#include "scan_test.h" +#include "_PDCLIB_test.h" -static int SCANFUNC( FILE * stream, char const * format, ... ) +static int testscanf( FILE * stream, char const * format, ... ) { va_list ap; va_start( ap, format ); @@ -96,10 +102,11 @@ static int SCANFUNC( FILE * stream, char const * format, ... ) int main( void ) { -#include "fscan_sources.incl" -#include "scanf_testcases.incl" + FILE * source; + TESTCASE( ( source = tmpfile() ) != NULL ); +#include "scanf_testcases.h" + TESTCASE( fclose( source ) == 0 ); return TEST_RESULTS; } #endif -