From a61ed2ce7a86a4d6428f2a83eb4739fae945447e Mon Sep 17 00:00:00 2001 From: Hans Rosenfeld Date: Sat, 1 Jul 2017 05:38:06 +0000 Subject: 12258 Need native CCID driver Contributed by: Robert Mustacchi Reviewed by: John Levon Reviewed by: Robert Mustacchi Approved by: Garrett D'Amore --- usr/src/lib/libcmdutils/common/nicenum.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'usr/src/lib/libcmdutils/common') diff --git a/usr/src/lib/libcmdutils/common/nicenum.c b/usr/src/lib/libcmdutils/common/nicenum.c index 8e3202f792..a9161c422c 100644 --- a/usr/src/lib/libcmdutils/common/nicenum.c +++ b/usr/src/lib/libcmdutils/common/nicenum.c @@ -22,6 +22,7 @@ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2017 Jason king + * Copyright 2019, Joyent, Inc. */ #include @@ -44,8 +45,13 @@ nicenum_scale(uint64_t n, size_t units, char *buf, size_t buflen, uint64_t divisor = 1; int index = 0; int rc = 0; + const char *spc = ""; char u; + if (flags & NN_UNIT_SPACE) { + spc = " "; + } + if (units == 0) units = 1; @@ -84,17 +90,17 @@ nicenum_scale(uint64_t n, size_t units, char *buf, size_t buflen, u = " KMGTPE"[index]; if (index == 0) { - rc = snprintf(buf, buflen, "%llu", n); + rc = snprintf(buf, buflen, "%llu%s", n, spc); } else if (n % divisor == 0) { /* * If this is an even multiple of the base, always display * without any decimal precision. */ - rc = snprintf(buf, buflen, "%llu%c", n / divisor, u); + rc = snprintf(buf, buflen, "%llu%s%c", n / divisor, spc, u); } else { /* * We want to choose a precision that reflects the best choice - * for fitting in 5 characters. This can get rather tricky + * for fitting in the buffer. This can get rather tricky * when we have numbers that are very close to an order of * magnitude. For example, when displaying 10239 (which is * really 9.999K), we want only a single place of precision @@ -104,8 +110,8 @@ nicenum_scale(uint64_t n, size_t units, char *buf, size_t buflen, */ int i; for (i = 2; i >= 0; i--) { - if ((rc = snprintf(buf, buflen, "%.*f%c", i, - (double)n / divisor, u)) <= 5) + if ((rc = snprintf(buf, buflen, "%.*f%s%c", i, + (double)n / divisor, spc, u)) <= (buflen - 1)) break; } } -- cgit v1.2.3