From 28a77abc18c1135a7a390e1aeb8a77a1d7bfacaf Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Mon, 25 Mar 2013 12:02:48 +1030 Subject: [PATCH] Add XPRINT strbuf adapter --- xprintf.c | 6 ++++++ xprintf.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/xprintf.c b/xprintf.c index cb532af4..6a3d00d7 100644 --- a/xprintf.c +++ b/xprintf.c @@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include +#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); +} diff --git a/xprintf.h b/xprintf.h index 1124ad35..4d5808bb 100644 --- a/xprintf.h +++ b/xprintf.h @@ -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