diff options
author | Andrea Adami <andrea.adami@gmail.com> | 2018-01-29 23:07:11 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2018-01-30 09:24:19 +0100 |
commit | 61afcc6f46368caf4b8eb64612decebb05fadba7 (patch) | |
tree | db7c5f6d05f9c3b2dc0a0c14d4496e4a62784724 /lib | |
parent | 6766178412934e29db12ff5e6663604c6e909c6e (diff) |
mtd-utils: common.c: convert to integer arithmetic
We use floating point just to print out KiB, MiB, GiB.
Avoid that to be klibc friendly.
Fixes compilation for aarch64 against klibc:
error: '-mgeneral-regs-only' is incompatible with floating-point argument
| printf("%s%.1f GiB", p, (double)bytes / (1024 * 1024 * 1024));
etc.
Signed-off-by: Andrea Adami <andrea.adami@gmail.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/common.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/common.c b/lib/common.c index 69b03b3..8041878 100644 --- a/lib/common.c +++ b/lib/common.c @@ -107,6 +107,9 @@ long long util_get_bytes(const char *str) void util_print_bytes(long long bytes, int bracket) { const char *p; + int GiB = 1024 * 1024 * 1024; + int MiB = 1024 * 1024; + int KiB = 1024; if (bracket) p = " ("; @@ -115,12 +118,15 @@ void util_print_bytes(long long bytes, int bracket) printf("%lld bytes", bytes); - if (bytes > 1024 * 1024 * 1024) - printf("%s%.1f GiB", p, (double)bytes / (1024 * 1024 * 1024)); - else if (bytes > 1024 * 1024) - printf("%s%.1f MiB", p, (double)bytes / (1024 * 1024)); - else if (bytes > 1024 && bytes != 0) - printf("%s%.1f KiB", p, (double)bytes / 1024); + if (bytes > GiB) + printf("%s%lld.%lld GiB", p, + bytes / GiB, bytes % GiB / (GiB / 10)); + else if (bytes > MiB) + printf("%s%lld.%lld MiB", p, + bytes / MiB, bytes % MiB / (MiB / 10)); + else if (bytes > KiB && bytes != 0) + printf("%s%lld.%lld KiB", p, + bytes / KiB, bytes % KiB / (KiB / 10)); else return; |