Regenerate.
[gnulib.git] / lib / human.h
1 /* human.h -- print human readable file size
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4    Free Software Foundation, Inc.
5
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)
9    any later version.
10
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.
15
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
19
20 /* Written by Paul Eggert and Larry McVoy.  */
21
22 #ifndef HUMAN_H_
23 # define HUMAN_H_ 1
24
25 # include <limits.h>
26 # include <stdbool.h>
27
28 # if HAVE_STDINT_H
29 #  include <stdint.h>
30 # endif
31 # if HAVE_UNISTD_H
32 #  include <unistd.h>
33 # endif
34
35 /* A conservative bound on the maximum length of a human-readable string.
36    The output can be the square of the largest uintmax_t, so double
37    its size before converting to a bound.
38    log10 (2.0) < 146/485.  Add 1 for integer division truncation.
39    Also, the output can have a thousands separator between every digit,
40    so multiply by MB_LEN_MAX + 1 and then subtract MB_LEN_MAX.
41    Append 1 for a space before the suffix.
42    Finally, append 3, the maximum length of a suffix.  */
43 # define LONGEST_HUMAN_READABLE \
44   ((2 * sizeof (uintmax_t) * CHAR_BIT * 146 / 485 + 1) * (MB_LEN_MAX + 1) \
45    - MB_LEN_MAX + 1 + 3)
46
47 /* Options for human_readable.  */
48 enum
49 {
50   /* Unless otherwise specified these options may be ORed together.  */
51
52   /* The following three options are mutually exclusive.  */
53   /* Round to plus infinity (default).  */
54   human_ceiling = 0,
55   /* Round to nearest, ties to even.  */
56   human_round_to_nearest = 1,
57   /* Round to minus infinity.  */
58   human_floor = 2,
59
60   /* Group digits together, e.g. `1,000,000'.  This uses the
61      locale-defined grouping; the traditional C locale does not group,
62      so this has effect only if some other locale is in use.  */
63   human_group_digits = 4,
64
65   /* When autoscaling, suppress ".0" at end.  */
66   human_suppress_point_zero = 8,
67
68   /* Scale output and use SI-style units, ignoring the output block size.  */
69   human_autoscale = 16,
70
71   /* Prefer base 1024 to base 1000.  */
72   human_base_1024 = 32,
73
74   /* Prepend " " before unit symbol.  */
75   human_space_before_unit = 64,
76
77   /* Append SI prefix, e.g. "k" or "M".  */
78   human_SI = 128,
79
80   /* Append "B" (if base 1000) or "iB" (if base 1024) to SI prefix.  */
81   human_B = 256
82 };
83
84 char *human_readable (uintmax_t, char *, int, uintmax_t, uintmax_t);
85
86 int human_options (char const *, bool, uintmax_t *);
87
88 #endif /* HUMAN_H_ */