]> pd.if.org Git - pdclib/blob - functions/stdio/fscanf.c
Started debugging scanf() functions.
[pdclib] / functions / stdio / fscanf.c
1 /* $Id$ */
2
3 /* fscanf( FILE *, const char *, ... )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #include <stdio.h>
10 #include <stdarg.h>
11
12 #ifndef REGTEST
13
14 int fscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... )
15 {
16     int rc;
17     va_list ap;
18     va_start( ap, format );
19     rc = vfscanf( stream, format, ap );
20     va_end( ap );
21     return rc;
22 }
23
24 #endif
25
26 #ifdef TEST
27 #include <_PDCLIB_test.h>
28
29 #include <limits.h>
30 #include <string.h>
31
32 int main( void )
33 {
34     char teststring1[] = "  1 23\045\0\067 ";
35     char buffer[15];
36     FILE * fh;
37     TESTCASE( ( fh = fopen( "testfile", "w+" ) ) != NULL );
38     TESTCASE( fwrite( teststring1, 15, 1, fh ) == 1 );
39     rewind( fh );
40     /* */
41     TESTCASE( memset( buffer, CHAR_MAX, 15 ) == buffer ); \
42     TESTCASE( fseek( fh, 0, SEEK_SET ) == 0 ); \
43     TESTCASE( fscanf( fh, "%14c", buffer ) == 1 ); \
44     TESTCASE( memcmp( buffer, teststring1 + 0, 14 ) == 0 ); \
45     TESTCASE( buffer[ 14 ] == CHAR_MAX ); \
46     TESTCASE( memset( buffer, CHAR_MAX, 15 ) == buffer ); \
47     TESTCASE( sscanf( teststring1 + 14, "%14c", buffer ) ); \
48     TESTCASE( memcmp( buffer, teststring1 + 0, 14 ) == 0 ); \
49     TESTCASE( buffer[ 14 ] == CHAR_MAX );
50     return TEST_RESULTS;
51 }
52
53 #endif