[RFC PATCH 4/8] vshPrint: Add version using 'va_list'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tools/vsh.c | 32 ++++++++++++++++++++++----------
 tools/vsh.h |  4 ++++
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 5b672b8edf..41f55a91fa 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -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;

+    str = g_strdup_vprintf(format, ap);
+    fputs(str, stdout);
+    fflush(stdout);
+}
+
+
+void
+vshPrintExtra(vshControl *ctl,
+              const char *format,
+              ...)
+{
+    va_list ap;
+
     if (ctl && ctl->quiet)
         return;

     va_start(ap, format);
-    str = g_strdup_vprintf(format, ap);
+    vshPrintVa(ctl, format, ap);
     va_end(ap);
-    fputs(str, stdout);
-    fflush(stdout);
 }


 void
-vshPrint(vshControl *ctl G_GNUC_UNUSED, const char *format, ...)
+vshPrint(vshControl *ctl,
+         const char *format,
+         ...)
 {
     va_list ap;
-    g_autofree char *str = NULL;

     va_start(ap, format);
-    str = g_strdup_vprintf(format, ap);
+    vshPrintVa(ctl, format, ap);
     va_end(ap);
-    fputs(str, stdout);
-    fflush(stdout);
 }


diff --git a/tools/vsh.h b/tools/vsh.h
index 51f09cd2b0..377c5947c1 100644
--- a/tools/vsh.h
+++ b/tools/vsh.h
@@ -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, ...)
-- 
2.39.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux