From 7f792cd7586b82bd1e8abd526963ca88413f3b5c Mon Sep 17 00:00:00 2001 From: Marcel Moolenaar Date: Tue, 18 Nov 2008 04:04:01 +0000 Subject: Use humanize_number(), rather than a home-grown algorithm for formatting a number in a human-friendly way. Note that with this commit a megabyte changed from 1000000 to 1048576 and a 80G disk is now printed as being 75G in size. This is deliberate. It's consistent with the core of geom(8). However, the original choice for a megabyte being 1000000 was on purpose and matches what disk vendors put on the box. The consistency is considered more important. Submitted by: delphij --- sbin/geom/class/part/Makefile | 2 ++ sbin/geom/class/part/geom_part.c | 18 +++++------------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/sbin/geom/class/part/Makefile b/sbin/geom/class/part/Makefile index 0588646f09b7..36227162a1f4 100644 --- a/sbin/geom/class/part/Makefile +++ b/sbin/geom/class/part/Makefile @@ -4,6 +4,8 @@ CLASS= part +LDADD= -lutil + WARNS?= 4 .include diff --git a/sbin/geom/class/part/geom_part.c b/sbin/geom/class/part/geom_part.c index 4264992df9eb..c5f8ebba0bbe 100644 --- a/sbin/geom/class/part/geom_part.c +++ b/sbin/geom/class/part/geom_part.c @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -203,21 +204,12 @@ find_provider(struct ggeom *gp, unsigned long long minsector) } static const char * -fmtsize(long double rawsz) +fmtsize(int64_t rawsz) { - static char buf[32]; - static const char *sfx[] = { "B", "KB", "MB", "GB", "TB" }; - long double sz; - int sfxidx; - - sfxidx = 0; - sz = (long double)rawsz; - while (sfxidx < 4 && sz > 1099.0) { - sz /= 1000; - sfxidx++; - } + static char buf[5]; - sprintf(buf, "%.1Lf%s", sz, sfx[sfxidx]); + humanize_number(buf, sizeof(buf), rawsz, "", HN_AUTOSCALE, + HN_B | HN_NOSPACE | HN_DECIMAL); return (buf); } -- cgit v1.3