summaryrefslogtreecommitdiff
path: root/lib/human.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1999-11-07 21:06:02 +0000
committerJim Meyering <jim@meyering.net>1999-11-07 21:06:02 +0000
commit41c5f76c2f50b39930de1e72cee95caadc9143a0 (patch)
treec2ba97f7ba342960fa5c038bde46e78c60f0a4af /lib/human.c
parent0b23ffc1bfb7f983e4808190a11bb6012bb82f16 (diff)
downloadcoreutils-41c5f76c2f50b39930de1e72cee95caadc9143a0.tar.xz
(default_block_size): New function.
(humblock): Use it if no block size is specified. (human_block_size): If the specified block size is zero, report an error if report_errors is nonzero; otherwise use the default.
Diffstat (limited to 'lib/human.c')
-rw-r--r--lib/human.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/human.c b/lib/human.c
index 6d91b8c1b..600614e01 100644
--- a/lib/human.c
+++ b/lib/human.c
@@ -276,13 +276,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 +312,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);
}