util: buffer: Add virBufferStrcatVArgs

Split out the worker loop into a separate function and export it.

Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Peter Krempa 2017-07-24 18:54:15 +02:00
parent 55e8314efd
commit 3c60388591
3 changed files with 24 additions and 6 deletions

View File

@ -1345,6 +1345,7 @@ virBufferFreeAndReset;
virBufferGetIndent; virBufferGetIndent;
virBufferSetIndent; virBufferSetIndent;
virBufferStrcat; virBufferStrcat;
virBufferStrcatVArgs;
virBufferTrim; virBufferTrim;
virBufferURIEncodeString; virBufferURIEncodeString;
virBufferUse; virBufferUse;

View File

@ -830,6 +830,26 @@ virBufferEscapeShell(virBufferPtr buf, const char *str)
VIR_FREE(escaped); VIR_FREE(escaped);
} }
/**
* virBufferStrcatVArgs:
* @buf: the buffer to append to
* @ap: variable argument structure
*
* See virBufferStrcat.
*/
void
virBufferStrcatVArgs(virBufferPtr buf,
va_list ap)
{
char *str;
if (buf->error)
return;
while ((str = va_arg(ap, char *)) != NULL)
virBufferAdd(buf, str, -1);
}
/** /**
* virBufferStrcat: * virBufferStrcat:
* @buf: the buffer to append to * @buf: the buffer to append to
@ -842,14 +862,9 @@ void
virBufferStrcat(virBufferPtr buf, ...) virBufferStrcat(virBufferPtr buf, ...)
{ {
va_list ap; va_list ap;
char *str;
if (buf->error)
return;
va_start(ap, buf); va_start(ap, buf);
while ((str = va_arg(ap, char *)) != NULL) virBufferStrcatVArgs(buf, ap);
virBufferAdd(buf, str, -1);
va_end(ap); va_end(ap);
} }

View File

@ -80,6 +80,8 @@ void virBufferVasprintf(virBufferPtr buf, const char *format, va_list ap)
ATTRIBUTE_FMT_PRINTF(2, 0); ATTRIBUTE_FMT_PRINTF(2, 0);
void virBufferStrcat(virBufferPtr buf, ...) void virBufferStrcat(virBufferPtr buf, ...)
ATTRIBUTE_SENTINEL; ATTRIBUTE_SENTINEL;
void virBufferStrcatVArgs(virBufferPtr buf, va_list ap);
void virBufferEscape(virBufferPtr buf, char escape, const char *toescape, void virBufferEscape(virBufferPtr buf, char escape, const char *toescape,
const char *format, const char *str); const char *format, const char *str);
void virBufferEscapeN(virBufferPtr buf, const char *format, void virBufferEscapeN(virBufferPtr buf, const char *format,