From c3d1d4654f01d13ecc50e459d4cec688323d709e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pali=20Roh=C3=A1r?= Date: Sun, 26 Dec 2021 22:12:00 +0100 Subject: [PATCH] lspci: Define PCI_U64_FMT_U format for printing u64 Windows CRTDLL and MSVCRT runtime system libraries do not support %llu format string in printf. They support only %I64u format string. Fix this problem by providing PCI_U64_FMT_U macro in the same way as existing PCI_U64_FMT_X macro (for %llx). For C99 systems this PCI_U64_FMT_U macro is defined to C99 PRIu64 constant. This change fixes printing unsigned decimal 64-bit numbers by lspci on Window systems independently of used compiler (MinGW or MSVC). --- lib/types.h | 4 ++++ ls-ecaps.c | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/types.h b/lib/types.h index 6fdfd09..243997f 100644 --- a/lib/types.h +++ b/lib/types.h @@ -18,6 +18,7 @@ typedef WORD u16; typedef DWORD u32; typedef unsigned __int64 u64; #define PCI_U64_FMT_X "I64x" +#define PCI_U64_FMT_U "I64u" #elif defined(PCI_HAVE_STDINT_H) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) /* Use standard types in C99 and newer */ @@ -28,6 +29,7 @@ typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; #define PCI_U64_FMT_X PRIx64 +#define PCI_U64_FMT_U PRIu64 #else /* Hope for POSIX types from */ @@ -40,9 +42,11 @@ typedef u_int32_t u32; #if ULONG_MAX > 0xffffffff typedef unsigned long u64; #define PCI_U64_FMT_X "lx" +#define PCI_U64_FMT_U "lu" #else typedef unsigned long long u64; #define PCI_U64_FMT_X "llx" +#define PCI_U64_FMT_U "llu" #endif #endif diff --git a/ls-ecaps.c b/ls-ecaps.c index bd29c99..2c0264e 100644 --- a/ls-ecaps.c +++ b/ls-ecaps.c @@ -67,12 +67,12 @@ cap_ltr(struct device *d, int where) snoop = get_conf_word(d, where + PCI_LTR_MAX_SNOOP); scale = cap_ltr_scale((snoop >> PCI_LTR_SCALE_SHIFT) & PCI_LTR_SCALE_MASK); - printf("\t\tMax snoop latency: %lldns\n", + printf("\t\tMax snoop latency: %" PCI_U64_FMT_U "ns\n", ((u64)snoop & PCI_LTR_VALUE_MASK) * scale); nosnoop = get_conf_word(d, where + PCI_LTR_MAX_NOSNOOP); scale = cap_ltr_scale((nosnoop >> PCI_LTR_SCALE_SHIFT) & PCI_LTR_SCALE_MASK); - printf("\t\tMax no snoop latency: %lldns\n", + printf("\t\tMax no snoop latency: %" PCI_U64_FMT_U "ns\n", ((u64)nosnoop & PCI_LTR_VALUE_MASK) * scale); } @@ -826,7 +826,7 @@ cap_l1pm(struct device *d, int where) if (scale > 5) printf(" LTR1.2_Threshold="); else - printf(" LTR1.2_Threshold=%lldns", BITS(val, 16, 10) * (u64) cap_ltr_scale(scale)); + printf(" LTR1.2_Threshold=%" PCI_U64_FMT_U "ns", BITS(val, 16, 10) * (u64) cap_ltr_scale(scale)); } printf("\n"); } -- 2.39.5