aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDima Dorfman <dd@FreeBSD.org>2002-10-18 04:06:59 +0000
committerDima Dorfman <dd@FreeBSD.org>2002-10-18 04:06:59 +0000
commit598420ee63bcd384feb9d3bfb8825f534d22d9b3 (patch)
tree658b1f41f230ef124b3b8a007a7e71ab4437a0cb /bin
parent64ac587b8a800cb52624596ae2f609243c99ca34 (diff)
downloadsrc-598420ee63bcd384feb9d3bfb8825f534d22d9b3.tar.gz
src-598420ee63bcd384feb9d3bfb8825f534d22d9b3.zip
Output "human-readable" values with a non-0 precision where
appropriate. Before this, a 2.9 GB file was misleadingly reported as "2G". This mostly brings unit_adjust() in line with what is in du(1). Reviewed by: jmallett Approved by: nik
Notes
Notes: svn path=/head/; revision=105375
Diffstat (limited to 'bin')
-rw-r--r--bin/ls/print.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/bin/ls/print.c b/bin/ls/print.c
index c6f15d3f7438..4f2907affe9f 100644
--- a/bin/ls/print.c
+++ b/bin/ls/print.c
@@ -93,7 +93,7 @@ static unsigned long long vals_base2[] = {1, KILO_2_SZ, MEGA_2_SZ, GIGA_2_SZ, TE
typedef enum {
NONE, KILO, MEGA, GIGA, TERA, PETA, UNIT_MAX
} unit_t;
-static unit_t unit_adjust(off_t *);
+static unit_t unit_adjust(double *);
static int unitp[] = {NONE, KILO, MEGA, GIGA, TERA, PETA};
@@ -602,16 +602,18 @@ printlink(FTSENT *p)
static void
printsize(size_t width, off_t bytes)
{
+ double dbytes;
unit_t unit;
if (f_humanval) {
- unit = unit_adjust(&bytes);
+ dbytes = bytes;
+ unit = unit_adjust(&dbytes);
- if (bytes == 0)
+ if (dbytes == 0)
(void)printf("%*s ", width, "0B");
else
- (void)printf("%*lld%c ", width - 1, bytes,
- "BKMGTPE"[unit]);
+ (void)printf("%*.*f%c ", width - 1, dbytes > 10 ? 0 : 1,
+ dbytes, "BKMGTPE"[unit]);
} else
(void)printf("%*lld ", width, bytes);
}
@@ -623,13 +625,13 @@ printsize(size_t width, off_t bytes)
*
*/
unit_t
-unit_adjust(off_t *val)
+unit_adjust(double *val)
{
double abval;
unit_t unit;
unsigned int unit_sz;
- abval = fabs((double)*val);
+ abval = fabs(*val);
unit_sz = abval ? ilogb(abval) / 10 : 0;