1 /* snprintf( char *, size_t, const char *, ... )
2 
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6 
7 #include <stdio.h>
8 #include <stdarg.h>
9 
10 #ifndef REGTEST
11 
snprintf(char * _PDCLIB_restrict s,size_t n,const char * _PDCLIB_restrict format,...)12 int snprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restrict format, ... )
13 {
14     int rc;
15     va_list ap;
16     va_start( ap, format );
17     rc = vsnprintf( s, n, format, ap );
18     va_end( ap );
19     return rc;
20 }
21 
22 #endif
23 
24 #ifdef TEST
25 #define _PDCLIB_FILEID "stdio/snprintf.c"
26 #define _PDCLIB_STRINGIO
27 #include <stdint.h>
28 #include <stddef.h>
29 
30 #include "_PDCLIB_test.h"
31 
32 #define testprintf( s, ... ) snprintf( s, 100, __VA_ARGS__ )
33 
main(void)34 int main( void )
35 {
36     char target[100];
37 #include "printf_testcases.h"
38     TESTCASE( snprintf( NULL, 0, "foo" ) == 3 );
39     TESTCASE( snprintf( NULL, 0, "%d", 100 ) == 3 );
40     return TEST_RESULTS;
41 }
42 
43 #endif
44