svn commit: r185046 - head/sbin/geom/class/part
Marcel Moolenaar
marcel at FreeBSD.org
Mon Nov 17 20:04:01 PST 2008
Author: marcel
Date: Tue Nov 18 04:04:01 2008
New Revision: 185046
URL: http://svn.freebsd.org/changeset/base/185046
Log:
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
Modified:
head/sbin/geom/class/part/Makefile
head/sbin/geom/class/part/geom_part.c
Modified: head/sbin/geom/class/part/Makefile
==============================================================================
--- head/sbin/geom/class/part/Makefile Tue Nov 18 03:55:55 2008 (r185045)
+++ head/sbin/geom/class/part/Makefile Tue Nov 18 04:04:01 2008 (r185046)
@@ -4,6 +4,8 @@
CLASS= part
+LDADD= -lutil
+
WARNS?= 4
.include <bsd.lib.mk>
Modified: head/sbin/geom/class/part/geom_part.c
==============================================================================
--- head/sbin/geom/class/part/geom_part.c Tue Nov 18 03:55:55 2008 (r185045)
+++ head/sbin/geom/class/part/geom_part.c Tue Nov 18 04:04:01 2008 (r185046)
@@ -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
}
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;
+ static char buf[5];
- sfxidx = 0;
- sz = (long double)rawsz;
- while (sfxidx < 4 && sz > 1099.0) {
- sz /= 1000;
- sfxidx++;
- }
-
- sprintf(buf, "%.1Lf%s", sz, sfx[sfxidx]);
+ humanize_number(buf, sizeof(buf), rawsz, "", HN_AUTOSCALE,
+ HN_B | HN_NOSPACE | HN_DECIMAL);
return (buf);
}
More information about the svn-src-head
mailing list