free.c - name correctly the binary multiples in the human-readable case
authorgetzze <getzze@gmail.com>
Fri, 4 Nov 2016 01:11:01 +0000 (01:11 +0000)
committerCraig Small <csmall@enc.com.au>
Sat, 13 Jan 2018 04:40:35 +0000 (15:40 +1100)
free.c

diff --git a/free.c b/free.c
index 5807e42cbe6f75d8548f3bce88d09b53a5028269..6d81548e0ac60955d7e1b0513cac09009661fcb5 100644 (file)
--- a/free.c
+++ b/free.c
@@ -152,14 +152,25 @@ static const char *scale_size(unsigned long size, int flags, struct commandline_
                case 4:
                case 5:
                case 6:
-            if (4 >=
-                snprintf(buf, sizeof(buf), "%.1f%c",
-                     (float)((size / 1024) * base / power(base, i - 2)), *up))
-                return buf;
-            if (4 >=
-                snprintf(buf, sizeof(buf), "%ld%c",
-                     (long)((size / 1024) * base / power(base, i - 2)), *up))
-                return buf;
+                       if (!(flags & FREE_SI)) {
+                               if (5 >=
+                                   snprintf(buf, sizeof(buf), "%.1f%ci",
+                                            (float)((size / 1024) * base / power(base, i - 2)), *up))
+                                       return buf;
+                               if (5 >=
+                                   snprintf(buf, sizeof(buf), "%ld%ci",
+                                            (long)((size / 1024) * base / power(base, i - 2)), *up))
+                                       return buf;
+                       } else {
+                               if (4 >=
+                                   snprintf(buf, sizeof(buf), "%.1f%c",
+                                            (float)((size / 1024) * base / power(base, i - 2)), *up))
+                                       return buf;
+                               if (4 >=
+                                   snprintf(buf, sizeof(buf), "%ld%c",
+                                            (long)((size / 1024) * base / power(base, i - 2)), *up))
+                                       return buf;
+                       }
                        break;
                case 7:
                        break;