changeset 14010:61e74b16a691

3668 add "%H" to mdb_printf() for human-readable sizes (fix kmdb)
author Bryan Cantrill <bryan@joyent.com>
date Thu, 11 Apr 2013 10:46:40 -0700
parents e08c4b83071d
children 779e63d911a5
files usr/src/cmd/mdb/common/mdb/mdb_io.c
diffstat 1 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/mdb/common/mdb/mdb_io.c	Wed Apr 10 13:37:31 2013 -0700
+++ b/usr/src/cmd/mdb/common/mdb/mdb_io.c	Thu Apr 11 10:46:40 2013 -0700
@@ -877,12 +877,17 @@
  * Produce human-readable size, similar in spirit (and identical in output)
  * to libzfs's zfs_nicenum() -- but made significantly more complicated by
  * the constraint that we cannot use snprintf() as an implementation detail.
+ * Recall, floating point is verboten in kmdb.
  */
 static const char *
 iob_bytes2str(varglist_t *ap, intsize_t size)
 {
+#ifndef _KMDB
 	const int sigfig = 3;
-	uint64_t n, orig;
+	uint64_t orig;
+#endif
+	uint64_t n;
+
 	static char buf[68], *c;
 	int index = 0;
 	char u;
@@ -903,7 +908,9 @@
 		n = (uint_t)VA_ARG(ap, uint_t);
 	}
 
+#ifndef _KMDB
 	orig = n;
+#endif
 
 	while (n >= 1024) {
 		n /= 1024;
@@ -915,12 +922,18 @@
 
 	if (index == 0) {
 		return (numtostr(n, 10, 0));
+#ifndef _KMDB
 	} else if ((orig & ((1ULL << 10 * index) - 1)) == 0) {
+#else
+	} else {
+#endif
 		/*
-		 * If this is an even multiple of the base, always display
-		 * without any decimal precision.
+		 * If this is an even multiple of the base or we are in an
+		 * environment where floating point is verboten (i.e., kmdb),
+		 * always display without any decimal precision.
 		 */
 		(void) strcat(buf, numtostr(n, 10, 0));
+#ifndef _KMDB
 	} else {
 		/*
 		 * We want to choose a precision that results in the specified
@@ -995,6 +1008,7 @@
 				break;
 			}
 		}
+#endif
 	}
 
 	c = &buf[strlen(buf)];