]> pd.if.org Git - pdclib/blob - functions/stdio/fprintf.c
e3fbdab0c048ea83d3b06dbe55799694cbc0cc01
[pdclib] / functions / stdio / fprintf.c
1 /* $Id$ */
2
3 /* fprintf( 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 fprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... )
15 {
16     int rc;
17     va_list ap;
18     va_start( ap, format );
19     rc = vfprintf( stream, format, ap );
20     va_end( ap );
21     return rc;
22 }
23
24 #endif
25
26 #ifdef TEST
27 #include <limits.h>
28 #include <string.h>
29 #include <_PDCLIB_test.h>
30
31 #define testprintf( stream, n, format, ... ) fprintf( stream, format, __VA_ARGS__ )
32
33 int main( void )
34 {
35     FILE * buffer;
36     TESTCASE( ( buffer = fopen( "testfile", "w" ) ) != NULL );
37 #include "printf_testcases.incl"
38     TESTCASE( fclose( buffer ) == 0 );
39     char readbuffer[1000];
40     TESTCASE( ( buffer = fopen( "testfile", "r" ) ) != NULL );
41     TESTCASE( fread( readbuffer, 1, 1000, buffer ) == 985 );
42     TESTCASE( fclose( buffer ) == 0 );
43     TESTCASE( remove( "testfile" ) == 0 );
44     TESTCASE( memcmp( readbuffer, "-1281270-32768327670-214748364821474836470-214748364821474836470-922337203685477580892233720368547758070255255655356553542949672954294967295429496729542949672951844674407370955161518446744073709551615FFFFFFFF0XFFFFFFFFffffffff0xffffffff37777777777037777777777%.0#o-2147483648+2147483647+042949672954294967295-2147483648 2147483647 042949672954294967295-21474836482147483647-21474836482147483647-2147483648 2147483647 -2147483648  2147483647-21474836482147483647-21474836482147483647-21474836482147483647 -2147483648 2147483647  -21474836482147483647-21474836482147483647-214748364802147483647-02147483648002147483647-21474836482147483647-21474836482147483647-21474836482147483647 -2147483648 2147483647            00000000002147483647ffffffff0xffffffff0xffffffff-2147483648-2147483648-21474836480xffffffff0xffffffff0xffffffff214748364721474836472147483647+2147483647+2147483647+2147483647+2147483647+2147483647+2147483647- 2147483647- 2147483647 % -2147483648xabcdef0xdeadbeef123456789", 985 ) == 0 );
45     return TEST_RESULTS;
46 }
47
48 #endif