From nobody Sun Apr 28 07:34:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554195125415136.17679219617264; Tue, 2 Apr 2019 01:52:05 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 14F1E308A946; Tue, 2 Apr 2019 08:52:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2954D5C290; Tue, 2 Apr 2019 08:52:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B8DE641F3D; Tue, 2 Apr 2019 08:52:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x328q0ej031439 for ; Tue, 2 Apr 2019 04:52:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2EB4364027; Tue, 2 Apr 2019 08:52:00 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-56.ams2.redhat.com [10.36.112.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A2816402D; Tue, 2 Apr 2019 08:51:53 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 2 Apr 2019 09:51:50 +0100 Message-Id: <20190402085150.23745-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] examples: fix 64-bit integer formatting on Windows X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 02 Apr 2019 08:52:04 +0000 (UTC) The Windows printf functions don't support %llu/%lld for printing 64-bit integers. For most of libvirt this doesn't matter as we rely on gnulib which provides a replacement printf that is sane. The example code is designed to compile against the normal OS headers, with no use of gnulib and thus has to use the platform specific printf. To deal with this we must use the macros PRI* macros from inttypes.h to get the platform specific format string. Signed-off-by: Daniel P. Berrang=C3=A9 --- examples/admin/client_info.c | 7 ++++--- examples/admin/list_clients.c | 3 ++- examples/domtop/domtop.c | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/admin/client_info.c b/examples/admin/client_info.c index f3f62a656b..d60512624d 100644 --- a/examples/admin/client_info.c +++ b/examples/admin/client_info.c @@ -3,6 +3,7 @@ #include #include #include +#include #include =20 static const char * @@ -66,11 +67,11 @@ exampleGetTypedParamValue(virTypedParameterPtr item) break; =20 case VIR_TYPED_PARAM_LLONG: - ret =3D asprintf(&str, "%lld", item->value.l); + ret =3D asprintf(&str, "%" PRId64, item->value.l); break; =20 case VIR_TYPED_PARAM_ULLONG: - ret =3D asprintf(&str, "%llu", item->value.ul); + ret =3D asprintf(&str, "%" PRIu64, item->value.ul); break; =20 case VIR_TYPED_PARAM_DOUBLE: @@ -143,7 +144,7 @@ int main(int argc, char **argv) if (!(timestr =3D exampleGetTimeStr(virAdmClientGetTimestamp(clnt)))) goto cleanup; =20 - printf("%-15s: %llu\n", "id", virAdmClientGetID(clnt)); + printf("%-15s: %" PRIu64 "\n", "id", virAdmClientGetID(clnt)); printf("%-15s: %s\n", "connection_time", timestr); printf("%-15s: %s\n", "transport", exampleTransportToString(virAdmClientGetTransport(clnt))); diff --git a/examples/admin/list_clients.c b/examples/admin/list_clients.c index 5cf8e4c2a6..545b9cbd01 100644 --- a/examples/admin/list_clients.c +++ b/examples/admin/list_clients.c @@ -1,6 +1,7 @@ #include #include #include +#include #include =20 static const char * @@ -96,7 +97,7 @@ int main(int argc, char **argv) exampleGetTimeStr(virAdmClientGetTimestamp(client)))) goto cleanup; =20 - printf(" %-5llu %-15s %-15s\n", id, + printf(" %-5" PRIu64 " %-15s %-15s\n", id, exampleTransportToString(transport), timestr); free(timestr); } diff --git a/examples/domtop/domtop.c b/examples/domtop/domtop.c index 008065c651..33d97c74fe 100644 --- a/examples/domtop/domtop.c +++ b/examples/domtop/domtop.c @@ -29,6 +29,7 @@ #include #include #include +#include =20 static bool debug; static bool run_top; @@ -226,7 +227,8 @@ print_cpu_usage(const char *dom_name, return; } =20 - DEBUG("now_params=3D%llu then_params=3D%llu now=3D%llu then=3D%llu= ", + DEBUG("now_params=3D%" PRIu64 " then_params=3D%" PRIu64 + " now=3D%" PRIu64 " then=3D%" PRIu64, now_params[pos].value.ul, then_params[pos].value.ul, now, th= en); =20 /* @now_params and @then_params are in nanoseconds, @now and @then= are --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list