X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lspci.c;h=54317cf5002f3395b8fad76ca0ce87bc88dfafa5;hb=refs%2Ftags%2Fv3.1.5;hp=e453f1bfb23d1855c559175db3319d0f4c56163b;hpb=659d438b89875f4a141e2e342b9378669b7a8572;p=pciutils.git diff --git a/lspci.c b/lspci.c index e453f1b..54317cf 100644 --- a/lspci.c +++ b/lspci.c @@ -330,18 +330,16 @@ show_terse(struct device *d) static void show_size(pciaddr_t x) { + static const char suffix[][2] = { "", "K", "M", "G", "T" }; + unsigned i; if (!x) return; - printf(" [size="); - if (x < 1024) - printf("%d", (int) x); - else if (x < 1048576) - printf("%dK", (int)(x / 1024)); - else if (x < 0x80000000) - printf("%dM", (int)(x / 1048576)); - else - printf(PCIADDR_T_FMT, x); - putchar(']'); + for (i = 0; i < (sizeof(suffix) / sizeof(*suffix) - 1); i++) { + if (x < 1024) + break; + x /= 1024; + } + printf(" [size=%u%s]", (unsigned)x, suffix[i]); } static void