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

[libvirt] [PATCH 8/4] examples: fix mingw build vs. printf



Mingw *printf is a moving target; newer mingw now provides a version
of asprintf() that fails to understand %lld:

  CC       event_test-event-test.o
../../../../examples/domain-events/events-c/event-test.c: In function 'myDomainEventRTCChangeCallback':
../../../../examples/domain-events/events-c/event-test.c:270:18: error: unknown conversion type character 'l' in format [-Werror=format=]
                  virDomainGetID(dom), offset) < 0)
                  ^

But since our examples already admitted that they were hacking around
a mingw deficiency, it is easier to just use printf() directly, coupled
with <inttypes.h> macros, for a more portable work-around.

* examples/domain-events/events-c/event-test.c
(myDomainEventRTCChangeCallback): Use PRIdMAX instead of asprintf.

Signed-off-by: Eric Blake <eblake redhat com>
---

Pushing under the build-breaker rule; and with this, I
_finally_ completed a run of ./autobuild.sh with a mingw
cross-compilation environment installed.

 examples/domain-events/events-c/event-test.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c
index fe4eb56..52aa3d0 100644
--- a/examples/domain-events/events-c/event-test.c
+++ b/examples/domain-events/events-c/event-test.c
@@ -262,16 +262,9 @@ static int myDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
                                           long long offset,
                                           void *opaque ATTRIBUTE_UNUSED)
 {
-    char *str = NULL;
-    /* HACK: use asprintf since we have gnulib's wrapper for %lld on Win32
-     * but don't have a printf() replacement with %lld */
-    if (asprintf(&str, "%s EVENT: Domain %s(%d) rtc change %lld\n",
-                 __func__, virDomainGetName(dom),
-                 virDomainGetID(dom), offset) < 0)
-        return 0;
-
-    printf("%s", str);
-    free(str);
+    printf("%s EVENT: Domain %s(%d) rtc change %" PRIdMAX "\n",
+           __func__, virDomainGetName(dom), virDomainGetID(dom),
+           (intmax_t)offset);

     return 0;
 }
-- 
1.8.3.1


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