]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: avoid mingw compiler warnings
authorEric Blake <eblake@redhat.com>
Sat, 12 Feb 2011 00:17:12 +0000 (17:17 -0700)
committerEric Blake <eblake@redhat.com>
Sat, 12 Feb 2011 13:39:27 +0000 (06:39 -0700)
Compilation on mingw was warning about %lld use in fprintf, and
in the gnulib strptime module about dead labels.

* tools/virsh.c (vshPrint): Change redirect.
(vshPrintExtra): Allow use within vshPrint.  Avoid fprintf on
arbitrary formats, since we aren't using gnulib module; instead,
use virVasprintf to pre-format.
(vshError): Likewise.
* .gnulib: Update to latest, for mingw strptime warning fix.
Reported by Matthias Bolte.

.gnulib
tools/virsh.c

diff --git a/.gnulib b/.gnulib
index 4cce65cb2f10936f13760625f39d532564984fde..ecb020f2b046790d76d05d377ca1e864e2bc9fdc 160000 (submodule)
--- a/.gnulib
+++ b/.gnulib
@@ -1 +1 @@
-Subproject commit 4cce65cb2f10936f13760625f39d532564984fde
+Subproject commit ecb020f2b046790d76d05d377ca1e864e2bc9fdc
index 6d9861fa1318186e423c992e542ade49b1e9ab7b..c2d165d34f8268bd41c6bb8c0b41576a9b77fbc8 100644 (file)
@@ -325,7 +325,7 @@ static void vshDebug(vshControl *ctl, int level, const char *format, ...)
     ATTRIBUTE_FMT_PRINTF(3, 4);
 
 /* XXX: add batch support */
-#define vshPrint(_ctl, ...)   fprintf(stdout, __VA_ARGS__)
+#define vshPrint(_ctl, ...)   vshPrintExtra(NULL, __VA_ARGS__)
 
 static const char *vshDomainStateToString(int state);
 static const char *vshDomainVcpuStateToString(int state);
@@ -11574,13 +11574,20 @@ static void
 vshPrintExtra(vshControl *ctl, const char *format, ...)
 {
     va_list ap;
+    char *str;
 
-    if (ctl->quiet == TRUE)
+    if (ctl && ctl->quiet == TRUE)
         return;
 
     va_start(ap, format);
-    vfprintf(stdout, format, ap);
+    if (virVasprintf(&str, format, ap) < 0) {
+        vshError(ctl, "%s", _("Out of memory"));
+        va_end(ap);
+        return;
+    }
     va_end(ap);
+    fprintf(stdout, "%s", str);
+    VIR_FREE(str);
 }
 
 
@@ -11588,6 +11595,7 @@ static void
 vshError(vshControl *ctl, const char *format, ...)
 {
     va_list ap;
+    char *str;
 
     if (ctl != NULL) {
         va_start(ap, format);
@@ -11598,10 +11606,13 @@ vshError(vshControl *ctl, const char *format, ...)
     fputs(_("error: "), stderr);
 
     va_start(ap, format);
-    vfprintf(stderr, format, ap);
+    /* We can't recursively call vshError on an OOM situation, so ignore
+       failure here. */
+    ignore_value(virVasprintf(&str, format, ap));
     va_end(ap);
 
-    fputc('\n', stderr);
+    fprintf(stderr, "%s\n", NULLSTR(str));
+    VIR_FREE(str);
 }
 
 /*