X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fhuman.c;h=7b923dc89df92fbe0dfa9d56b73d656d2f6e7861;hb=e911cfd715b17d7314df5882f00b86a2cef6c3ad;hp=d03a2e4e47829a2e87ae72bb06105bfa404325e9;hpb=23360fcb0a3b5440391e54f9037ea8f3bbed391c;p=gnulib.git diff --git a/lib/human.c b/lib/human.c index d03a2e4e4..7b923dc89 100644 --- a/lib/human.c +++ b/lib/human.c @@ -1,5 +1,5 @@ /* human.c -- print human readable file size - Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. + Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,10 +23,6 @@ # include #endif -#if HAVE_INTTYPES_H -# include -#endif - #include #include @@ -34,6 +30,12 @@ # include #endif +#if HAVE_STRING_H +# include +#else +# include +#endif + #ifndef CHAR_BIT # define CHAR_BIT 8 #endif @@ -54,7 +56,7 @@ char *getenv (); #include #include -#include +#include #include "human.h" @@ -74,7 +76,7 @@ static const char suffixes[] = /* Convert N to a human readable format in BUF. N is expressed in units of FROM_BLOCK_SIZE. FROM_BLOCK_SIZE must - be positive. + be nonnegative. If OUTPUT_BLOCK_SIZE is positive, use units of OUTPUT_BLOCK_SIZE in the output number. OUTPUT_BLOCK_SIZE must be a multiple of @@ -99,7 +101,7 @@ human_readable (uintmax_t n, char *buf, uintmax_t amt; int base; int to_block_size; - int tenths; + int tenths = 0; int power; char *p; @@ -107,7 +109,7 @@ human_readable (uintmax_t n, char *buf, 1 means AMT.TENTHS < adjusted N < AMT.TENTHS + 0.05; 2 means adjusted N == AMT.TENTHS + 0.05; 3 means AMT.TENTHS + 0.05 < adjusted N < AMT.TENTHS + 0.1. */ - int rounding; + int rounding = 0; if (output_block_size < 0) { @@ -134,7 +136,6 @@ human_readable (uintmax_t n, char *buf, { int multiplier = from_block_size / to_block_size; amt = n * multiplier; - tenths = rounding = 0; if (amt / multiplier != n) { @@ -170,6 +171,8 @@ human_readable (uintmax_t n, char *buf, return buf; } } + else if (from_block_size == 0) + amt = 0; else { int divisor = to_block_size / from_block_size; @@ -258,7 +261,7 @@ humblock (char const *spec, int *block_size) if (! spec && ! (spec = getenv ("BLOCK_SIZE"))) *block_size = getenv ("POSIXLY_CORRECT") ? 512 : DEFAULT_BLOCK_SIZE; - else if (0 <= (i = argmatch (spec, block_size_args))) + else if (0 <= (i = ARGMATCH (spec, block_size_args, block_size_types))) *block_size = block_size_types[i]; else {