diff options
author | Hans Rosenfeld <hans.rosenfeld@joyent.com> | 2020-01-12 01:01:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-12 01:01:41 +0100 |
commit | b44b91e41531b86f9807aecf62d96cad6f2f06cd (patch) | |
tree | 1fe4c2409126f74cddb013d220c824367d9dc788 /usr/src/lib/libcmdutils/common/nicenum.c | |
parent | 8b175886ef45935e972cf1df20218f2de66d49b1 (diff) | |
download | illumos-joyent-b44b91e41531b86f9807aecf62d96cad6f2f06cd.tar.gz |
OS-7196 Need native CCID driver
Contributed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: John Levon <john.levon@joyent.com>
Approved by: Jason King <jbk@joyent.com>
Diffstat (limited to 'usr/src/lib/libcmdutils/common/nicenum.c')
-rw-r--r-- | usr/src/lib/libcmdutils/common/nicenum.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/usr/src/lib/libcmdutils/common/nicenum.c b/usr/src/lib/libcmdutils/common/nicenum.c index 8e3202f792..9b9a8fcd5e 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 <stdio.h> @@ -44,8 +45,15 @@ nicenum_scale(uint64_t n, size_t units, char *buf, size_t buflen, uint64_t divisor = 1; int index = 0; int rc = 0; + int spclen = 0; + char *spc = ""; char u; + if (flags & NN_UNIT_SPACE) { + spc = " "; + spclen = 1; + } + if (units == 0) units = 1; @@ -90,7 +98,7 @@ nicenum_scale(uint64_t n, size_t units, char *buf, size_t buflen, * 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 @@ -104,8 +112,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)) <= 5 + spclen) break; } } |