]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
lib: sprint_size(): Uncrustify the code a bit
authorPetr Machata <me@pmachata.org>
Sat, 5 Dec 2020 21:13:32 +0000 (22:13 +0100)
committerDavid Ahern <dsahern@gmail.com>
Wed, 9 Dec 2020 02:30:36 +0000 (02:30 +0000)
Ideally this and the rate printing would both be converted to a common
helper, but unfortunately the two format differently and this would break
tests and scripts out there. So just make the code look less like a wad of
hay.

Signed-off-by: Petr Machata <me@pmachata.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
lib/json_print.c

index c1df637642fd6d6369f6efe3f885aee05a46e055..d28e957c96033a8f100c03ce1924e7e162ada841 100644 (file)
@@ -344,13 +344,15 @@ int print_color_rate(bool use_iec, enum output_type type, enum color_attr color,
 
 char *sprint_size(__u32 sz, char *buf)
 {
+       long kilo = 1024;
+       long mega = kilo * kilo;
        size_t len = SPRINT_BSIZE - 1;
        double tmp = sz;
 
-       if (sz >= 1024*1024 && fabs(1024*1024*rint(tmp/(1024*1024)) - sz) < 1024)
-               snprintf(buf, len, "%gMb", rint(tmp/(1024*1024)));
-       else if (sz >= 1024 && fabs(1024*rint(tmp/1024) - sz) < 16)
-               snprintf(buf, len, "%gKb", rint(tmp/1024));
+       if (sz >= mega && fabs(mega * rint(tmp / mega) - sz) < 1024)
+               snprintf(buf, len, "%gMb", rint(tmp / mega));
+       else if (sz >= kilo && fabs(kilo * rint(tmp / kilo) - sz) < 16)
+               snprintf(buf, len, "%gKb", rint(tmp / kilo));
        else
                snprintf(buf, len, "%ub", sz);