X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdio%2F_cbprintf.c;fp=functions%2Fstdio%2F_cbprintf.c;h=c0192fe0f331a581549c311517372a517e24c1fc;hb=af7b48b211498ff4ef7aba6db89b90b760cdd3d5;hp=0000000000000000000000000000000000000000;hpb=b7a3e4143b3b837d8309624ec120d53cbd409058;p=pdclib diff --git a/functions/stdio/_cbprintf.c b/functions/stdio/_cbprintf.c new file mode 100644 index 0000000..c0192fe --- /dev/null +++ b/functions/stdio/_cbprintf.c @@ -0,0 +1,56 @@ +/* _cbprintf( void *, size_t (*)( void*, const char *, size_t ), const char *, ... ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include +#include +#include + +#ifndef REGTEST + +int _cbprintf( + void * p, + size_t (*cb)( void*, const char*, size_t ), + const char * _PDCLIB_restrict format, + ...) +{ + int rc; + va_list ap; + va_start( ap, format ); + rc = _vcbprintf( p, cb, format, ap ); + va_end( ap ); + return rc; +} + +#endif + +#ifdef TEST +#define _PDCLIB_FILEID "stdio/sprintf.c" +#define _PDCLIB_STRINGIO +#include + +#include <_PDCLIB_test.h> + +static char * bufptr; +static size_t testcb( void *p, const char *buf, size_t size ) +{ + memcpy(bufptr, buf, size); + bufptr += size; + *bufptr = '\0'; + return size; +} + +#define testprintf( s, ... ) _cbprintf( bufptr = s, testcb, __VA_ARGS__ ) + +int main( void ) +{ + char target[100]; +#ifndef REGTEST +#include "printf_testcases.h" +#endif + return TEST_RESULTS; +} + +#endif