diff options
author | Pali Rohár <pali@kernel.org> | 2021-12-26 22:12:00 +0100 |
---|---|---|
committer | Martin Mares <mj@ucw.cz> | 2022-02-10 12:58:17 +0100 |
commit | c3d1d4654f01d13ecc50e459d4cec688323d709e (patch) | |
tree | a5671ed4abef0efe138166dda5da9ab7973e07b9 | |
parent | 6811edb82791b1cc18889062a226522b7cdd74a8 (diff) | |
download | pciutils-c3d1d4654f01d13ecc50e459d4cec688323d709e.tar.gz |
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).
-rw-r--r-- | lib/types.h | 4 | ||||
-rw-r--r-- | 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 <sys/types.h> */ @@ -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 @@ -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=<error>"); 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"); } |