3 /* vfscanf( FILE *, const char *, va_list )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
14 #include <_PDCLIB_io.h>
16 int vfscanf_unlocked( FILE * _PDCLIB_restrict stream,
17 const char * _PDCLIB_restrict format,
20 /* TODO: This function should interpret format as multibyte characters. */
21 struct _PDCLIB_status_t status;
30 status.stream = stream;
31 va_copy( status.arg, arg );
33 while ( *format != '\0' )
36 if ( ( *format != '%' ) || ( ( rc = _PDCLIB_scan( format, &status ) ) == format ) )
39 /* No conversion specifier, match verbatim */
40 if ( isspace( *format ) )
42 /* Whitespace char in format string: Skip all whitespaces */
43 /* No whitespaces in input does not result in matching error */
44 while ( isspace( c = getc( stream ) ) )
48 if ( ! feof( stream ) )
55 /* Non-whitespace char in format string: Match verbatim */
56 if ( ( ( c = getc( stream ) ) != *format ) || feof( stream ) )
59 if ( ! feof( stream ) && ! ferror( stream ) )
63 else if ( status.n == 0 )
78 /* NULL return code indicates matching error */
83 /* Continue parsing after conversion specifier */
91 int vfscanf( FILE * _PDCLIB_restrict stream,
92 const char * _PDCLIB_restrict format,
96 int r = vfscanf_unlocked( stream, format, arg );
97 funlockfile( stream );
104 #define _PDCLIB_FILEID "stdio/vfscanf.c"
105 #define _PDCLIB_FILEIO
107 #include <_PDCLIB_test.h>
109 static int testscanf( FILE * stream, char const * format, ... )
112 va_start( ap, format );
113 int result = vfscanf( stream, format, ap );
121 TESTCASE( ( source = tmpfile() ) != NULL );
122 #include "scanf_testcases.h"
123 TESTCASE( fclose( source ) == 0 );