msgbuf: implement msgbuf_vunparse_fmt() and friends
This commit is contained in:
parent
691adddd0e
commit
8f64d32533
1 changed files with 40 additions and 0 deletions
|
@ -183,3 +183,43 @@ msgbuf_unparse(char *buf, size_t buflen, struct MsgBuf *msgbuf, unsigned int cap
|
||||||
|
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue