summaryrefslogtreecommitdiffstats
path: root/bin/ls
diff options
context:
space:
mode:
authordd <dd@FreeBSD.org>2002-10-18 04:06:59 +0000
committerdd <dd@FreeBSD.org>2002-10-18 04:06:59 +0000
commit8b821f23e8469b7446e2355c7401ffef219407d3 (patch)
tree658b1f41f230ef124b3b8a007a7e71ab4437a0cb /bin/ls
parent7185b416e63bb44056224c5342d0cfd9317ce336 (diff)
downloadFreeBSD-src-8b821f23e8469b7446e2355c7401ffef219407d3.zip
FreeBSD-src-8b821f23e8469b7446e2355c7401ffef219407d3.tar.gz
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
Diffstat (limited to 'bin/ls')
-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 c6f15d3..4f2907a 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;
OpenPOWER on IntegriCloud