From nobody Sat Apr 27 17:59:50 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 1554197271651526.8331282427963; Tue, 2 Apr 2019 02:27:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A6FF3086223; Tue, 2 Apr 2019 09:27:50 +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 A07E8600C7; Tue, 2 Apr 2019 09:27:49 +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 CFB4F41F3D; Tue, 2 Apr 2019 09:27:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x329PHAY003403 for ; Tue, 2 Apr 2019 05:25:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id AB5636141; Tue, 2 Apr 2019 09:25:17 +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 9AF9A58BB; Tue, 2 Apr 2019 09:25:00 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 2 Apr 2019 10:24:57 +0100 Message-Id: <20190402092457.30616-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 02 Apr 2019 09:27:51 +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 | 8 ++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) Changed in v2: - Now actually commit the int64 casts diff --git a/examples/admin/client_info.c b/examples/admin/client_info.c index f3f62a656b..7fc6c72bbd 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, (int64_t)item->value.l); break; =20 case VIR_TYPED_PARAM_ULLONG: - ret =3D asprintf(&str, "%llu", item->value.ul); + ret =3D asprintf(&str, "%" PRIu64, (uint64_t)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", (uint64_t)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..2876637d42 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", (uint64_t)id, exampleTransportToString(transport), timestr); free(timestr); } diff --git a/examples/domtop/domtop.c b/examples/domtop/domtop.c index 008065c651..e1e7fbff8b 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,8 +227,11 @@ print_cpu_usage(const char *dom_name, return; } =20 - DEBUG("now_params=3D%llu then_params=3D%llu now=3D%llu then=3D%llu= ", - now_params[pos].value.ul, then_params[pos].value.ul, now, th= en); + DEBUG("now_params=3D%" PRIu64 " then_params=3D%" PRIu64 + " now=3D%" PRIu64 " then=3D%" PRIu64, + (uint64_t)now_params[pos].value.ul, + (uint64_t)then_params[pos].value.ul, + (uint64_t)now, (uint64_t)then); =20 /* @now_params and @then_params are in nanoseconds, @now and @then= are * in microseconds. In ideal world, we would translate them both i= nto --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list