3 /* vsnprintf( char *, size_t, const char *, va_list ap )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
14 #include <_PDCLIB_io.h>
16 /* returns true if callback-based output succeeded; else false */
17 static inline bool cbout(
18 struct _PDCLIB_status_t * status,
22 size_t rv = status->write( status->ctx, buf, size );
29 size_t ( *cb ) ( void *p, const char *buf, size_t size ),
33 struct _PDCLIB_status_t status;
43 va_copy( status.arg, arg );
45 /* Alternate between outputing runs of verbatim text and conversions */
46 while ( *format != '\0' )
48 const char *mark = format;
49 while ( *format != '\0' && *format != '%')
56 if ( !cbout(&status, mark, format - mark) )
60 if ( *format == '%' ) {
61 int consumed = _PDCLIB_print( format, &status );
66 else if ( consumed == 0 )
68 /* not a conversion specifier, print verbatim */
69 if ( !cbout(&status, format++, 1) )
74 /* I/O callback error */
87 #define _PDCLIB_FILEID "stdio/_vcbprintf.c"
88 #define _PDCLIB_STRINGIO
91 #include <_PDCLIB_test.h>
95 static size_t testcb( void *p, const char *buf, size_t size )
98 memcpy(*destbuf, buf, size);
103 static int testprintf( char * s, const char * format, ... )
107 va_start( arg, format );
108 i = _vcbprintf( &s, testcb, format, arg );
120 #include "printf_testcases.h"