X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstdio%2Ffscanf.c;h=9bb775ffc6597178c5dc811b12b760127e951bef;hp=17b0dca4c9add00de4e45f667628696d137f3c5e;hb=da0f3f353d417fed71f358a48d5d5394145e460d;hpb=526e9954c39f30819e421cb74e82aa59d5a41013 diff --git a/functions/stdio/fscanf.c b/functions/stdio/fscanf.c index 17b0dca..9bb775f 100644 --- a/functions/stdio/fscanf.c +++ b/functions/stdio/fscanf.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /* fscanf( FILE *, const char *, ... ) This file is part of the Public Domain C Library (PDCLib). @@ -10,8 +8,21 @@ #include #ifndef REGTEST +#include "_PDCLIB_io.h" + +int _PDCLIB_fscanf_unlocked( FILE * _PDCLIB_restrict stream, + const char * _PDCLIB_restrict format, ... ) +{ + int rc; + va_list ap; + va_start( ap, format ); + rc = _PDCLIB_vfscanf_unlocked( stream, format, ap ); + va_end( ap ); + return rc; +} -int fscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... ) +int fscanf( FILE * _PDCLIB_restrict stream, + const char * _PDCLIB_restrict format, ... ) { int rc; va_list ap; @@ -24,57 +35,19 @@ int fscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format #endif #ifdef TEST -#include <_PDCLIB_test.h> +#define _PDCLIB_FILEID "stdio/fscanf.c" +#define _PDCLIB_FILEIO -#include +#include "_PDCLIB_test.h" -char scanstring[] = " 1 23\00045\000\00067 "; - -void scantest( int testnr, FILE * fh, size_t position, char const * format, - int expected_fscan_rc, char const * expected_fscan_output, size_t expected_fscan_length, - int expected_sscan_rc, char const * expected_sscan_output, size_t expected_sscan_length ) -{ - char buffer[15]; - printf( "Test %d\n", testnr ); - TESTCASE( memset( buffer, -1, 15 ) == buffer ); - TESTCASE( fseek( fh, position, SEEK_SET ) == 0 ); - TESTCASE( fscanf( fh, format, buffer ) == expected_fscan_rc ); - TESTCASE( memcmp( buffer, expected_fscan_output, expected_fscan_length ) == 0 ); - TESTCASE( memset( buffer, -1, 15 ) == buffer ); - TESTCASE( sscanf( scanstring + position, format, buffer ) == expected_sscan_rc ); - TESTCASE( memcmp( buffer, expected_sscan_output, expected_sscan_length ) == 0 ); -} +#define testscanf( stream, format, ... ) fscanf( stream, format, __VA_ARGS__ ) int main( void ) { - FILE * fh; - TESTCASE( ( fh = fopen( "testfile", "w+" ) ) != NULL ); - TESTCASE( fwrite( scanstring, 14, 1, fh ) == 1 ); - rewind( fh ); - - /* %14c - full scan */ - scantest( 1, fh, 0, "%14c", - 1, " 1 23\00045\000\00067 \377", 15, - 1, " 1 23\377", 7 ); - - /* %c - default to one, reading whitespace */ - scantest( 2, fh, 0, "%c", - 1, " \377", 2, - 1, " \377", 2 ); - - /* %1c - reading zero byte */ - scantest( 3, fh, 9, "%1c", - 1, "\000\377", 2, - -1, "\377", 1 ); - - /* %0c - NOT reading EOF */ - scantest( 4, fh, 13, "%0c", - 0, "\377", 1, - 0, "\377", 1 ); - - TESTCASE( fclose( fh ) == 0 ); - //TESTCASE( remove( "testfile" ) == 0 ); - + FILE * source; + TESTCASE( ( source = tmpfile() ) != NULL ); +#include "scanf_testcases.h" + TESTCASE( fclose( source ) == 0 ); return TEST_RESULTS; }