Add XPRINT strbuf adapter

This commit is contained in:
Andrew Bettison 2013-03-25 12:02:48 +10:30
parent 74adb2038a
commit 28a77abc18
2 changed files with 12 additions and 0 deletions

View File

@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <stdio.h>
#include <stdlib.h>
#include "strbuf.h"
#include "xprintf.h"
void xprintf(XPRINTF xfp, const char *fmt, ...)
@ -89,3 +90,8 @@ void _cx_vprintf_mallocbuf(void *context, const char *fmt, va_list ap)
}
}
}
void _cx_vprintf_strbuf(void *context, const char *fmt, va_list ap)
{
strbuf_vsprintf((strbuf)context, fmt, ap);
}

View File

@ -99,4 +99,10 @@ struct mallocbuf {
#define XPRINTF_MALLOCBUF(MB) _XPRINTF(_cx_vprintf_mallocbuf, (MB))
CONTEXT_VPRINTF _cx_vprintf_mallocbuf;
/* Strbuf adapter. An XPRINTF constructed with XPRINTF_STRBUF(sb) will write
* all its output to the give strbuf using strbuf_sprintf(sb,...).
*/
#define XPRINTF_STRBUF(SB) _XPRINTF(_cx_vprintf_strbuf,(SB))
CONTEXT_VPRINTF _cx_vprintf_strbuf;
#endif // __SERVALD_XPRINTF_H