diff options
author | marcel <marcel@FreeBSD.org> | 2008-11-18 04:04:01 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2008-11-18 04:04:01 +0000 |
commit | f9226694db55935726acca900e71e7fa685f80b1 (patch) | |
tree | f29b2aceca0a9b58c5f9105ca9b1497c3fd113b9 /sbin/geom | |
parent | 95c0784d70e1c15b79d2cf53b44d3218452fc200 (diff) | |
download | FreeBSD-src-f9226694db55935726acca900e71e7fa685f80b1.zip FreeBSD-src-f9226694db55935726acca900e71e7fa685f80b1.tar.gz |
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
Diffstat (limited to 'sbin/geom')
-rw-r--r-- | sbin/geom/class/part/Makefile | 2 | ||||
-rw-r--r-- | 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 0588646..3622716 100644 --- a/sbin/geom/class/part/Makefile +++ b/sbin/geom/class/part/Makefile @@ -4,6 +4,8 @@ CLASS= part +LDADD= -lutil + WARNS?= 4 .include <bsd.lib.mk> diff --git a/sbin/geom/class/part/geom_part.c b/sbin/geom/class/part/geom_part.c index 4264992..c5f8ebb 100644 --- a/sbin/geom/class/part/geom_part.c +++ b/sbin/geom/class/part/geom_part.c @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include <errno.h> #include <fcntl.h> #include <libgeom.h> +#include <libutil.h> #include <paths.h> #include <stdint.h> #include <stdio.h> @@ -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); } |