+
+
+/* The default block size used for output. This number may change in
+ the future as disks get larger. */
+#ifndef DEFAULT_BLOCK_SIZE
+# define DEFAULT_BLOCK_SIZE 1024
+#endif
+
+static char const *const block_size_args[] = { "human-readable", "si", 0 };
+static int const block_size_types[] = { -1024, -1000 };
+
+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;
+ else if (0 <= (i = argmatch (spec, block_size_args)))
+ *block_size = block_size_types[i];
+ else
+ {
+ char *ptr;
+ unsigned long val;
+ strtol_error e = xstrtoul (spec, &ptr, 0, &val, "eEgGkKmMpPtTyYzZ0");
+ if (e != LONGINT_OK)
+ return e;
+ if (*ptr)
+ return LONGINT_INVALID_SUFFIX_CHAR;
+ if ((int) val < 0 || val != (int) val)
+ return LONGINT_OVERFLOW;
+ *block_size = (int) val;
+ }
+
+ return LONGINT_OK;
+}
+
+void
+human_block_size (char const *spec, int report_errors, int *block_size)
+{
+ strtol_error e = humblock (spec, block_size);
+ if (e != LONGINT_OK && report_errors)
+ STRTOL_FATAL_ERROR (spec, _("block size"), e);
+}