]> git.ipfire.org Git - thirdparty/pciutils.git/commitdiff
lspci: Define PCI_U64_FMT_U format for printing u64
authorPali Rohár <pali@kernel.org>
Sun, 26 Dec 2021 21:12:00 +0000 (22:12 +0100)
committerMartin Mares <mj@ucw.cz>
Thu, 10 Feb 2022 11:58:17 +0000 (12:58 +0100)
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
ls-ecaps.c

index 6fdfd099f39ad8bfe56a2dda379a8fe94901af09..243997fa7a7da91a11386e1b207c84b0001653e2 100644 (file)
@@ -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
index bd29c998940873b7fcd5e229ca40e93798a3430a..2c0264eb72706c19711008a6c4dfba9419593ad7 100644 (file)
@@ -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");
     }