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
This commit is contained in:
parent
caab1f000c
commit
7f792cd758
@ -4,6 +4,8 @@
|
||||
|
||||
CLASS= part
|
||||
|
||||
LDADD= -lutil
|
||||
|
||||
WARNS?= 4
|
||||
|
||||
.include <bsd.lib.mk>
|
||||
|
@ -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;
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user