From 8f64d3253323059ca2b8dd324d68ed5dcd64cd5b Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 20 Feb 2016 11:38:00 -0600 Subject: [PATCH] msgbuf: implement msgbuf_vunparse_fmt() and friends --- ircd/msgbuf.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/ircd/msgbuf.c b/ircd/msgbuf.c index 3e3bebc1..ac7609a7 100644 --- a/ircd/msgbuf.c +++ b/ircd/msgbuf.c @@ -183,3 +183,43 @@ msgbuf_unparse(char *buf, size_t buflen, struct MsgBuf *msgbuf, unsigned int cap return 0; } + +/* + * unparse a MsgBuf stem + format string into a buffer + * if origin is NULL, me.name will be used. + * cmd may not be NULL. + * returns 0 on success, 1 on error. + */ +int +msgbuf_vunparse_fmt(char *buf, size_t buflen, struct MsgBuf *head, unsigned int capmask, const char *fmt, va_list va) +{ + char *ws; + size_t prefixlen; + + msgbuf_unparse_prefix(buf, buflen, head, capmask); + prefixlen = strlen(buf); + + ws = buf + prefixlen; + vsnprintf(ws, buflen - prefixlen, fmt, va); + + return 0; +} + +/* + * unparse a MsgBuf stem + format string into a buffer (with va_list handling) + * if origin is NULL, me.name will be used. + * cmd may not be NULL. + * returns 0 on success, 1 on error. + */ +int +msgbuf_unparse_fmt(char *buf, size_t buflen, struct MsgBuf *head, unsigned int capmask, const char *fmt, ...) +{ + va_list va; + int res; + + va_start(va, fmt); + res = msgbuf_vunparse_fmt(buf, buflen, head, capmask, fmt, va); + va_end(va); + + return res; +}