Date: Wed, 16 Oct 2002 02:38:21 +0000 From: Dima Dorfman <dima@trit.org> To: joe@freebsd.org, nik@freebsd.org Cc: audit@freebsd.org Subject: ls -h precision Message-ID: <20021016023821.GC27804@trit.org>
next in thread | raw e-mail | index | archive | help
When the -h option was added to ls(1), the unit_adjust() routine, which was borrowed from du(1), was changed from taking a double to an off_t. Is there a reason for this change that I'm missing? Changing it back and making the appropriate changes to the caller greatly improves the usefulness of -h. E.g., this file: -rw-r--r-- 1 dima wheel 3070535680 Jan 25 2002 lambda-a.20001129 is reported like this with -h as it is right now: -rw-r--r-- 1 dima wheel 2G Jan 25 2002 lambda-a.20001129 which is somewhat less than useful, since this file is much closer to 3G than 2G. With the attached patch, it is reported like this: -rw-r--r-- 1 dima wheel 2.9G Jan 25 2002 lambda-a.20001129 Any reason this shouldn't be implemented? Other comments? Thanks in advance, Dima. Index: print.c =================================================================== RCS file: /ref/cvsf/src/bin/ls/print.c,v retrieving revision 1.57 diff -u -r1.57 print.c --- print.c 29 Aug 2002 14:29:09 -0000 1.57 +++ print.c 16 Oct 2002 02:37:09 -0000 @@ -93,7 +93,7 @@ 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 @@ 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 @@ * */ 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; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021016023821.GC27804>