1 /* vfscanf( FILE *, const char *, va_list )
3 This file is part of the Public Domain C Library (PDCLib).
4 Permission is granted to use, modify, and / or redistribute at will.
12 #include "_PDCLIB_io.h"
14 int _PDCLIB_vfscanf_unlocked( FILE * _PDCLIB_restrict stream,
15 const char * _PDCLIB_restrict format,
18 /* TODO: This function should interpret format as multibyte characters. */
19 struct _PDCLIB_status_t status;
28 status.stream = stream;
29 va_copy( status.arg, arg );
31 while ( *format != '\0' )
34 if ( ( *format != '%' ) || ( ( rc = _PDCLIB_scan( format, &status ) ) == format ) )
37 /* No conversion specifier, match verbatim */
38 if ( isspace( *format ) )
40 /* Whitespace char in format string: Skip all whitespaces */
41 /* No whitespaces in input does not result in matching error */
42 while ( isspace( c = getc( stream ) ) )
46 if ( ! feof( stream ) )
48 _PDCLIB_ungetc_unlocked( c, stream );
53 /* Non-whitespace char in format string: Match verbatim */
54 if ( ( ( c = _PDCLIB_getc_unlocked( stream ) ) != *format ) || feof( stream ) )
57 if ( ! feof( stream ) && ! ferror( stream ) )
59 _PDCLIB_ungetc_unlocked( c, stream );
61 else if ( status.n == 0 )
76 /* NULL return code indicates matching error */
81 /* Continue parsing after conversion specifier */
89 int vfscanf( FILE * _PDCLIB_restrict stream,
90 const char * _PDCLIB_restrict format,
93 _PDCLIB_flockfile( stream );
94 int r = _PDCLIB_vfscanf_unlocked( stream, format, arg );
95 _PDCLIB_funlockfile( stream );
102 #define _PDCLIB_FILEID "stdio/vfscanf.c"
103 #define _PDCLIB_FILEIO
105 #include "_PDCLIB_test.h"
107 static int testscanf( FILE * stream, char const * format, ... )
110 va_start( ap, format );
111 int result = vfscanf( stream, format, ap );
119 TESTCASE( ( source = tmpfile() ) != NULL );
120 #include "scanf_testcases.h"
121 TESTCASE( fclose( source ) == 0 );