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.
15 int vfscanf_unlocked( FILE * _PDCLIB_restrict stream,
16 const char * _PDCLIB_restrict format,
19 /* TODO: This function should interpret format as multibyte characters. */
20 struct _PDCLIB_status_t status;
29 status.stream = stream;
30 va_copy( status.arg, arg );
32 while ( *format != '\0' )
35 if ( ( *format != '%' ) || ( ( rc = _PDCLIB_scan( format, &status ) ) == format ) )
38 /* No conversion specifier, match verbatim */
39 if ( isspace( *format ) )
41 /* Whitespace char in format string: Skip all whitespaces */
42 /* No whitespaces in input does not result in matching error */
43 while ( isspace( c = getc( stream ) ) )
47 if ( ! feof( stream ) )
54 /* Non-whitespace char in format string: Match verbatim */
55 if ( ( ( c = getc( stream ) ) != *format ) || feof( stream ) )
58 if ( ! feof( stream ) && ! ferror( stream ) )
62 else if ( status.n == 0 )
77 /* NULL return code indicates matching error */
82 /* Continue parsing after conversion specifier */
90 int vfscanf( FILE * _PDCLIB_restrict stream,
91 const char * _PDCLIB_restrict format,
95 int r = vfscanf_unlocked( stream, format, arg );
96 funlockfile( stream );
103 #define _PDCLIB_FILEID "stdio/vfscanf.c"
104 #define _PDCLIB_FILEIO
106 #include <_PDCLIB_test.h>
108 static int testscanf( FILE * stream, char const * format, ... )
111 va_start( ap, format );
112 int result = vfscanf( stream, format, ap );
120 TESTCASE( ( source = tmpfile() ) != NULL );
121 #include "scanf_testcases.h"
122 TESTCASE( fclose( source ) == 0 );