netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2] ip: fix spelling of "Ki" IEC prefix
@ 2019-12-12 21:54 Jakub Wilk
  2019-12-14 23:48 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Wilk @ 2019-12-12 21:54 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

The symbol for binary prefix kibi is "Ki", with uppercase K.
In contrast, the symbol for decimal kilo is lowercase "k".

Signed-off-by: Jakub Wilk <jwilk@jwilk.net>
---
 ip/ipaddress.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 964f14df..511ca6a8 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -551,7 +551,8 @@ static void print_vfinfo(FILE *fp, struct ifinfomsg *ifi, struct rtattr *vfinfo)
 
 void print_num(FILE *fp, unsigned int width, uint64_t count)
 {
-	const char *prefix = "kMGTPE";
+	const char *prefixes = "kMGTPE";
+	char prefix;
 	const unsigned int base = use_iec ? 1024 : 1000;
 	uint64_t powi = 1;
 	uint16_t powj = 1;
@@ -571,9 +572,9 @@ void print_num(FILE *fp, unsigned int width, uint64_t count)
 		if (count / base < powi)
 			break;
 
-		if (!prefix[1])
+		if (!prefixes[1])
 			break;
-		++prefix;
+		++prefixes;
 	}
 
 	/* try to guess a good number of digits for precision */
@@ -583,8 +584,11 @@ void print_num(FILE *fp, unsigned int width, uint64_t count)
 			break;
 	}
 
+	prefix = *prefixes;
+	if (use_iec && prefix == 'k')
+		prefix = 'K';
 	snprintf(buf, sizeof(buf), "%.*f%c%s", precision,
-		 (double) count / powi, *prefix, use_iec ? "i" : "");
+		 (double) count / powi, prefix, use_iec ? "i" : "");
 
 	fprintf(fp, "%-*s ", width, buf);
 }
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-14 23:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-12 21:54 [PATCH iproute2] ip: fix spelling of "Ki" IEC prefix Jakub Wilk
2019-12-14 23:48 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).