summaryrefslogtreecommitdiff
path: root/usr/src/lib/libcmdutils
diff options
context:
space:
mode:
authorHans Rosenfeld <hans.rosenfeld@joyent.com>2017-07-01 05:38:06 +0000
committerHans Rosenfeld <hans.rosenfeld@joyent.com>2020-03-27 20:09:43 +0100
commita61ed2ce7a86a4d6428f2a83eb4739fae945447e (patch)
treef9fbcbacc85a9ab1881c1a0447a0c712f93c43d1 /usr/src/lib/libcmdutils
parentae6d4bc342613e6a5dc7b84b03ecdb0cc9cf7d26 (diff)
downloadillumos-joyent-a61ed2ce7a86a4d6428f2a83eb4739fae945447e.tar.gz
12258 Need native CCID driver
Contributed by: Robert Mustacchi <rm@joyent.com> Reviewed by: John Levon <john.levon@joyent.com> Reviewed by: Robert Mustacchi <rm@fingolfin.org> Approved by: Garrett D'Amore <garrett@damore.org>
Diffstat (limited to 'usr/src/lib/libcmdutils')
-rw-r--r--usr/src/lib/libcmdutils/common/nicenum.c16
-rw-r--r--usr/src/lib/libcmdutils/libcmdutils.h3
2 files changed, 13 insertions, 6 deletions
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 <stdio.h>
@@ -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;
}
}
diff --git a/usr/src/lib/libcmdutils/libcmdutils.h b/usr/src/lib/libcmdutils/libcmdutils.h
index c9a61aab4d..54c025c9d9 100644
--- a/usr/src/lib/libcmdutils/libcmdutils.h
+++ b/usr/src/lib/libcmdutils/libcmdutils.h
@@ -26,7 +26,7 @@
* Copyright (c) 2013 RackTop Systems.
*/
/*
- * Copyright 2018 Joyent, Inc.
+ * Copyright 2019 Joyent, Inc.
*/
/*
@@ -163,6 +163,7 @@ extern int findnextuid(uid_t, uid_t, uid_t *);
extern int findnextgid(gid_t, gid_t, gid_t *);
#define NN_DIVISOR_1000 (1U << 0)
+#define NN_UNIT_SPACE (1U << 1)
/* Minimum size for the output of nicenum, including NULL */
#define NN_NUMBUF_SZ (6)