diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1999-01-31 18:28:30 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1999-01-31 18:28:30 +0000 |
commit | 3b9b932e9a8c5afd5438f8d93bf20a7f032d8847 (patch) | |
tree | a88c1e6c6354d350212ff92477db0ab58d1ad48c /bin/df/df.c | |
parent | c2ae597a496a66466fb1cd1fb02d5d450e3b06a8 (diff) |
When adjusting units for -h mode, use the absolute value to check for
kb, mega, giga, etc. Based on a change from kstailey@openbsd.org but
fixed differently.
Diffstat (limited to 'bin/df/df.c')
-rw-r--r-- | bin/df/df.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/bin/df/df.c b/bin/df/df.c index 31831028fb6..e52b2258fa7 100644 --- a/bin/df/df.c +++ b/bin/df/df.c @@ -1,4 +1,4 @@ -/* $OpenBSD: df.c,v 1.22 1998/08/18 23:03:32 deraadt Exp $ */ +/* $OpenBSD: df.c,v 1.23 1999/01/31 18:28:29 millert Exp $ */ /* $NetBSD: df.c,v 1.21.2.1 1995/11/01 00:06:11 jtc Exp $ */ /* @@ -49,7 +49,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)df.c 8.7 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: df.c,v 1.22 1998/08/18 23:03:32 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: df.c,v 1.23 1999/01/31 18:28:29 millert Exp $"; #endif #endif /* not lint */ @@ -60,6 +60,7 @@ static char rcsid[] = "$OpenBSD: df.c,v 1.22 1998/08/18 23:03:32 deraadt Exp $"; #include <err.h> #include <errno.h> #include <fcntl.h> +#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -301,23 +302,25 @@ unit_t unit_adjust(val) double *val; { + double abval; unit_t unit; - if (*val < 1024) + abval = fabs(*val); + if (abval < 1024) unit = NONE; - else if (*val < 1048576ULL) { + else if (abval < 1048576ULL) { unit = KILO; *val /= 1024; - } else if (*val < 1073741824ULL) { + } else if (abval < 1073741824ULL) { unit = MEGA; *val /= 1048576; - } else if (*val < 1099511627776ULL) { + } else if (abval < 1099511627776ULL) { unit = GIGA; *val /= 1073741824ULL; - } else if (*val < 1125899906842624ULL) { + } else if (abval < 1125899906842624ULL) { unit = TERA; *val /= 1099511627776ULL; - } else if (*val < 1152921504606846976ULL) { + } else if (abval < 1152921504606846976ULL) { unit = PETA; *val /= 1125899906842624ULL; } |