]> xenbits.xensource.com Git - libvirt.git/commitdiff
examples: Work around mingw printf() weakness
authorEric Blake <eblake@redhat.com>
Tue, 8 Jan 2019 19:46:48 +0000 (13:46 -0600)
committerEric Blake <eblake@redhat.com>
Tue, 8 Jan 2019 20:46:35 +0000 (14:46 -0600)
mingw lacks %lld and %zu support in printf(); we were getting it
from gnulib. But since commit acf522e8 stopped linking examples
against gnulib, we are getting a build failure due to -Wformat
flagging these strings. Keep the examples standalone, and work
around mingw by using manual casts to types we can portably print.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
examples/domtop/domtop.c
examples/object-events/event-test.c

index 4224e4c9ec8b28dc6fdae6683a32f549303e2982..ada5a064fb01cc03bb991152bf3a60f21eefe077 100644 (file)
@@ -241,7 +241,8 @@ print_cpu_usage(const char *dom_name,
 
         if (delim)
             printf("\t");
-        printf("CPU%zu: %.2lf", cpu + i, usage);
+        /* mingw lacks %zu */
+        printf("CPU%u: %.2lf", (unsigned)(cpu + i), usage);
         delim = true;
     }
 
index 53d95b10d07d12ce42a26920e1758e3a25a53125..0c99fb33e38dc7941d8c45fbd7ac3dec10862e52 100644 (file)
@@ -948,10 +948,11 @@ myDomainEventBlockThresholdCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
                                     unsigned long long excess,
                                     void *opaque ATTRIBUTE_UNUSED)
 {
+    /* Casts to uint64_t to work around mingw not knowing %lld */
     printf("%s EVENT: Domain %s(%d) block threshold callback dev '%s'(%s), "
-           "threshold: '%llu', excess: '%llu'",
+           "threshold: '%" PRIu64 "', excess: '%" PRIu64 "'",
            __func__, virDomainGetName(dom), virDomainGetID(dom),
-           dev, NULLSTR(path), threshold, excess);
+           dev, NULLSTR(path), (uint64_t)threshold, (uint64_t)excess);
     return 0;
 }