Also check for the log_user method, to avoid
[coreutils.git] / lib / human.h
blob343fff7e8990f57989381c3eed143d2a937b69ed
1 #ifndef HUMAN_H_
2 # define HUMAN_H_ 1
4 /* Before including this file, you need something like the following:
6 #if HAVE_CONFIG_H
7 # include <config.h>
8 #endif
10 #if HAVE_STDBOOL_H
11 # include <stdbool.h>
12 #else
13 typedef enum {false = 0, true = 1} bool;
14 #endif
16 #if HAVE_INTTYPES_H
17 # include <inttypes.h>
18 #else
19 # if HAVE_STDINT_H
20 # include <stdint.h>
21 # endif
22 #endif
24 #include <limits.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) \
37 - MB_LEN_MAX + 3)
39 /* Options for human_readable. */
40 enum
42 /* Unless otherwise specified these options may be ORed together. */
44 /* The following three options are mutually exclusive. */
45 /* Round to plus infinity (default). */
46 human_ceiling = 0,
47 /* Round to nearest, ties to even. */
48 human_round_to_nearest = 1,
49 /* Round to minus infinity. */
50 human_floor = 2,
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. */
61 human_autoscale = 16,
63 /* Prefer base 1024 to base 1000. */
64 human_base_1024 = 32,
66 /* Append SI prefix, e.g. "k" or "M". */
67 human_SI = 64,
69 /* Append "B" (if base 1000) or "iB" (if base 1024) to SI prefix. */
70 human_B = 128
73 char *human_readable (uintmax_t, char *, int, uintmax_t, uintmax_t);
75 int human_options (char const *, bool, uintmax_t *);
77 #endif /* HUMAN_H_ */