From owner-freebsd-audit Tue Oct 15 19:38:26 2002 Delivered-To: freebsd-audit@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DCE9437B401; Tue, 15 Oct 2002 19:38:23 -0700 (PDT) Received: from phalanx.trit.org (phalanx.trit.org [63.198.170.138]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5359443E6E; Tue, 15 Oct 2002 19:38:23 -0700 (PDT) (envelope-from dima@trit.org) Received: from sparkie.trit.org (sparkie.trit.org [192.168.4.16]) by phalanx.trit.org (Postfix) with ESMTP id 0CEE91A1BC; Wed, 16 Oct 2002 02:38:23 +0000 (UTC) Received: (from dima@localhost) by sparkie.trit.org (8.10.2+Sun/8.10.2) id g9G2cMV05497; Wed, 16 Oct 2002 02:38:22 GMT X-Authentication-Warning: sparkie.trit.org: dima set sender to dima@trit.org using -f Date: Wed, 16 Oct 2002 02:38:21 +0000 From: Dima Dorfman To: joe@freebsd.org, nik@freebsd.org Cc: audit@freebsd.org Subject: ls -h precision Message-ID: <20021016023821.GC27804@trit.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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