X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fhuman.c;h=5cfbce9df4ddef46b66ab67d8b1216f759344985;hb=abde38362f9239723c9b762d1b2ac41af575e6d5;hp=6d91b8c1b7f00012484d2a46b822c6dab86cc74a;hpb=f1d774407b15a379d9344c67cc4fde585af5cc2a;p=gnulib.git diff --git a/lib/human.c b/lib/human.c index 6d91b8c1b..5cfbce9df 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, 1999 Free Software Foundation, Inc. + Copyright (C) 1996, 1997, 1998, 1999, 2000 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 @@ -44,6 +44,9 @@ #endif #ifndef HAVE_DECL_GETENV +"this configure-time declaration test was not run" +#endif +#if !HAVE_DECL_GETENV char *getenv (); #endif @@ -276,13 +279,19 @@ human_readable_inexact (uintmax_t n, char *buf, static char const *const block_size_args[] = { "human-readable", "si", 0 }; static int const block_size_types[] = { -1024, -1000 }; +static int +default_block_size (void) +{ + return getenv ("POSIXLY_CORRECT") ? 512 : DEFAULT_BLOCK_SIZE; +} + static strtol_error humblock (char const *spec, int *block_size) { int i; if (! spec && ! (spec = getenv ("BLOCK_SIZE"))) - *block_size = getenv ("POSIXLY_CORRECT") ? 512 : DEFAULT_BLOCK_SIZE; + *block_size = default_block_size (); else if (0 <= (i = ARGMATCH (spec, block_size_args, block_size_types))) *block_size = block_size_types[i]; else @@ -306,6 +315,11 @@ void human_block_size (char const *spec, int report_errors, int *block_size) { strtol_error e = humblock (spec, block_size); + if (*block_size == 0) + { + *block_size = default_block_size (); + e = LONGINT_INVALID; + } if (e != LONGINT_OK && report_errors) STRTOL_FATAL_ERROR (spec, _("block size"), e); }