]> pd.if.org Git - pdclib/blob - functions/stdio/sprintf.c
Improved reporting by printf tests.
[pdclib] / functions / stdio / sprintf.c
1 /* $Id$ */
2
3 /* sprintf( char *, 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 <stdint.h>
11 #include <stdarg.h>
12
13 #ifndef REGTEST
14
15 int sprintf( char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, ...)
16 {
17     int rc;
18     va_list ap;
19     va_start( ap, format );
20     rc = vsnprintf( s, SIZE_MAX, format, ap ); /* TODO: replace with non-checking call */
21     va_end( ap );
22     return rc;
23 }
24
25 #endif
26
27 #ifdef TEST
28 #include <_PDCLIB_test.h>
29
30 #include <string.h>
31 #include <limits.h>
32
33 #define testprintf( s, n, format, ... ) sprintf( s, format, __VA_ARGS__ )
34
35 #define TESTCASE_SPRINTF( x ) if ( strcmp( buffer, x ) == 0 ) {} \
36                               else { TEST_RESULTS += 1; printf( "FAILED: " __FILE__ ", line %d - \"%s\" != %s\n", __LINE__, buffer, #x ); }
37
38 int main( void )
39 {
40     char buffer[100];
41 #include "printf_testcases.incl"
42     return TEST_RESULTS;
43 }
44
45 #endif