From 939d2bf46ca1a5b9f80410f0be2bfd6d4bf84647 Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Sat, 15 Jun 2013 12:12:21 +0100 Subject: [PATCH] Addition of a version of printf that can print to a DCB --- core/dcb.c | 24 ++++++++++++++++++++++++ include/dcb.h | 1 + 2 files changed, 25 insertions(+) diff --git a/core/dcb.c b/core/dcb.c index 95d5c8a0c..8f5c3f847 100644 --- a/core/dcb.c +++ b/core/dcb.c @@ -26,6 +26,7 @@ * */ #include +#include #include #include #include @@ -216,3 +217,26 @@ gw_dcb_state2string (int state) { return "DCB (unknown)"; } } + +/* + * A DCB based wrapper for printf. Allows formattign printing to + * a descritor control block. + * + * @param dcb Descriptor to write to + * @param fmt A printf format string + * @param ... Variable arguments for the print format + */ +void +dcb_printf(DCB *dcb, const char *fmt, ...) +{ +GWBUF *buf; +va_list args; + + if ((buf = gwbuf_alloc(10240)) == NULL) + return; + va_start(args, fmt); + vsnprintf(GWBUF_DATA(buf), 10240, fmt, args); + va_end(args); + + dcb->func.write(dcb, buf); +} diff --git a/include/dcb.h b/include/dcb.h index 13efaee5f..b734177ee 100644 --- a/include/dcb.h +++ b/include/dcb.h @@ -106,5 +106,6 @@ extern DCB *connect_dcb(struct server *, struct session *, const char *); extern void printAllDCBs(); /* Debug to print all DCB in the system */ extern void printDCB(DCB *); /* Debug print routine */ extern const char *gw_dcb_state2string(int); /* DCB state to string */ +extern void dcb_printf(DCB *, const char *, ...); /* DCB version of printf */ #endif