1 /* human.h -- print human readable file size
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free
4 Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 /* Written by Paul Eggert and Larry McVoy. */
33 # include <inttypes.h>
40 /* A conservative bound on the maximum length of a human-readable string.
41 The output can be the square of the largest uintmax_t, so double
42 its size before converting to a bound.
43 302 / 1000 is ceil (log10 (2.0)). Add 1 for integer division truncation.
44 Also, the output can have a thousands separator between every digit,
45 so multiply by MB_LEN_MAX + 1 and then subtract MB_LEN_MAX.
46 Finally, append 3, the maximum length of a suffix. */
47 # define LONGEST_HUMAN_READABLE \
48 ((2 * sizeof (uintmax_t) * CHAR_BIT * 302 / 1000 + 1) * (MB_LEN_MAX + 1) \
51 /* Options for human_readable. */
54 /* Unless otherwise specified these options may be ORed together. */
56 /* The following three options are mutually exclusive. */
57 /* Round to plus infinity (default). */
59 /* Round to nearest, ties to even. */
60 human_round_to_nearest
= 1,
61 /* Round to minus infinity. */
64 /* Group digits together, e.g. `1,000,000'. This uses the
65 locale-defined grouping; the traditional C locale does not group,
66 so this has effect only if some other locale is in use. */
67 human_group_digits
= 4,
69 /* When autoscaling, suppress ".0" at end. */
70 human_suppress_point_zero
= 8,
72 /* Scale output and use SI-style units, ignoring the output block size. */
75 /* Prefer base 1024 to base 1000. */
78 /* Append SI prefix, e.g. "k" or "M". */
81 /* Append "B" (if base 1000) or "iB" (if base 1024) to SI prefix. */
85 char *human_readable (uintmax_t, char *, int, uintmax_t, uintmax_t);
87 int human_options (char const *, bool, uintmax_t *);