Subject: Re: Suggestion for changes to df(1) and du(1)
To: Tomas Svensson <tsn@gbdev.net>
From: Brian Grayson \(home\) <bgrayson@austin.rr.com>
List: tech-userlevel
Date: 11/18/2001 22:03:52
On Mon, Nov 19, 2001 at 03:44:36AM +0100, Tomas Svensson wrote:
> Hi,
> 
> Does anyone have an opinion about adding the flag -h to df(1) and du(1)?
> It would be to print the statistics in a more "human-readable" and 
> compact style.
...
> @@ -62,6 +62,7 @@
>  #include <err.h>
>  #include <errno.h>
>  #include <fcntl.h>
> +#include <math.h>
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>

  Hm.  Maybe I'm being paranoid, but I don't really see anything in
the code below that _requires_ FP math.  You can pass the size in
bytes in long-longs, replace the call to fabs() with an assignment and a
simple check (abytes = bytes;  if (abytes < 0) {abytes *= -1;}),
and replace the printouts by printing (bytes/10) . (bytes%10).

  Since du doesn't currently use anything from libm or math.h, it
seems a shame to pull it in, for those architectures where floating
point is emulated, in a very important system utility.  Then again, du
and df are probably going to spend so many milliseconds talking to the
disk, that a few microseconds to emulate a little math, and a few
extra bytes/Kbytes in the executable size, may be in the noise.

  Brian