]> pd.if.org Git - pdclib.old/blob - functions/stdio/_cbprintf.c
[gandr] s/__lp64__/__LP64__/ to match GCC define
[pdclib.old] / functions / stdio / _cbprintf.c
1 /* _cbprintf( void *, size_t (*)( void*, const 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 <stdint.h>
9 #include <stdarg.h>
10
11 #ifndef REGTEST
12
13 int _cbprintf(
14     void * p,
15     size_t (*cb)( void*, const char*, size_t ),
16     const char * _PDCLIB_restrict format,
17     ...)
18 {
19     int rc;
20     va_list ap;
21     va_start( ap, format );
22     rc = _vcbprintf( p, cb, format, ap );
23     va_end( ap );
24     return rc;
25 }
26
27 #endif
28
29 #ifdef TEST
30 #define _PDCLIB_FILEID "stdio/sprintf.c"
31 #define _PDCLIB_STRINGIO
32 #include <stddef.h>
33
34 #include <_PDCLIB_test.h>
35
36 static char * bufptr;
37 static size_t testcb( void *p, const char *buf, size_t size )
38 {
39     memcpy(bufptr, buf, size);
40     bufptr += size;
41     *bufptr = '\0';
42     return size;
43 }
44
45 #define testprintf( s, ... ) _cbprintf( bufptr = s, testcb, __VA_ARGS__ )
46
47 int main( void )
48 {
49     char target[100];
50 #ifndef REGTEST
51 #include "printf_testcases.h"
52 #endif
53     return TEST_RESULTS;
54 }
55
56 #endif