4 /* Before including this file, you need something like the following:
13 typedef enum {false = 0, true = 1} bool;
17 # include <inttypes.h>
26 so that the proper identifiers are all declared. */
28 /* A conservative bound on the maximum length of a human-readable string.
29 The output can be the square of the largest uintmax_t, so double
30 its size before converting to a bound.
31 302 / 1000 is ceil (log10 (2.0)). Add 1 for integer division truncation.
32 Also, the output can have a thousands separator between every digit,
33 so multiply by MB_LEN_MAX + 1 and then subtract MB_LEN_MAX.
34 Finally, append 3, the maximum length of a suffix. */
35 # define LONGEST_HUMAN_READABLE \
36 ((2 * sizeof (uintmax_t) * CHAR_BIT * 302 / 1000 + 1) * (MB_LEN_MAX + 1) \
39 /* Options for human_readable. */
42 /* Unless otherwise specified these options may be ORed together. */
44 /* The following three options are mutually exclusive. */
45 /* Round to plus infinity (default). */
47 /* Round to nearest, ties to even. */
48 human_round_to_nearest
= 1,
49 /* Round to minus infinity. */
52 /* Group digits together, e.g. `1,000,000'. This uses the
53 locale-defined grouping; the traditional C locale does not group,
54 so this has effect only if some other locale is in use. */
55 human_group_digits
= 4,
57 /* When autoscaling, suppress ".0" at end. */
58 human_suppress_point_zero
= 8,
60 /* Scale output and use SI-style units, ignoring the output block size. */
63 /* Prefer base 1024 to base 1000. */
66 /* Append SI prefix, e.g. "k" or "M". */
69 /* Append "B" (if base 1000) or "iB" (if base 1024) to SI prefix. */
73 char *human_readable (uintmax_t, char *, int, uintmax_t, uintmax_t);
75 int human_options (char const *, bool, uintmax_t *);