vshPrint: Add version using 'va_list'

Add a version for functions which may already need to take a printf
format string.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2023-04-13 09:19:27 +02:00
parent 620d942749
commit 13af21fb74
2 changed files with 28 additions and 12 deletions

View File

@ -1865,34 +1865,46 @@ vshDebug(vshControl *ctl, int level, const char *format, ...)
fflush(stdout);
}
void
vshPrintExtra(vshControl *ctl, const char *format, ...)
vshPrintVa(vshControl *ctl G_GNUC_UNUSED,
const char *format,
va_list ap)
{
va_list ap;
g_autofree char *str = NULL;
if (ctl && ctl->quiet)
return;
va_start(ap, format);
str = g_strdup_vprintf(format, ap);
va_end(ap);
fputs(str, stdout);
fflush(stdout);
}
void
vshPrint(vshControl *ctl G_GNUC_UNUSED, const char *format, ...)
vshPrintExtra(vshControl *ctl,
const char *format,
...)
{
va_list ap;
g_autofree char *str = NULL;
if (ctl && ctl->quiet)
return;
va_start(ap, format);
str = g_strdup_vprintf(format, ap);
vshPrintVa(ctl, format, ap);
va_end(ap);
}
void
vshPrint(vshControl *ctl,
const char *format,
...)
{
va_list ap;
va_start(ap, format);
vshPrintVa(ctl, format, ap);
va_end(ap);
fputs(str, stdout);
fflush(stdout);
}

View File

@ -302,6 +302,10 @@ const vshCmdOpt *vshCommandOptArgv(vshControl *ctl, const vshCmd *cmd,
bool vshCommandArgvParse(vshControl *ctl, int nargs, char **argv);
int vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, int *timeout);
void vshPrintVa(vshControl *ctl,
const char *format,
va_list ap)
G_GNUC_PRINTF(2, 0);
void vshPrint(vshControl *ctl, const char *format, ...)
G_GNUC_PRINTF(2, 3);
void vshPrintExtra(vshControl *ctl, const char *format, ...)