]> git.cworth.org Git - tar/blob - gnu/human.h
upstream: Fix extraction of device nodes.
[tar] / gnu / human.h
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* human.h -- print human readable file size
4
5    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
6    2006, 2007, 2009, 2010 Free Software Foundation, Inc.
7
8    This program is free software: you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20
21 /* Written by Paul Eggert and Larry McVoy.  */
22
23 #ifndef HUMAN_H_
24 # define HUMAN_H_ 1
25
26 # include <limits.h>
27 # include <stdbool.h>
28 # include <stdint.h>
29 # include <unistd.h>
30
31 # include <xstrtol.h>
32
33 /* A conservative bound on the maximum length of a human-readable string.
34    The output can be the square of the largest uintmax_t, so double
35    its size before converting to a bound.
36    log10 (2.0) < 146/485.  Add 1 for integer division truncation.
37    Also, the output can have a thousands separator between every digit,
38    so multiply by MB_LEN_MAX + 1 and then subtract MB_LEN_MAX.
39    Append 1 for a space before the suffix.
40    Finally, append 3, the maximum length of a suffix.  */
41 # define LONGEST_HUMAN_READABLE \
42   ((2 * sizeof (uintmax_t) * CHAR_BIT * 146 / 485 + 1) * (MB_LEN_MAX + 1) \
43    - MB_LEN_MAX + 1 + 3)
44
45 /* Options for human_readable.  */
46 enum
47 {
48   /* Unless otherwise specified these options may be ORed together.  */
49
50   /* The following three options are mutually exclusive.  */
51   /* Round to plus infinity (default).  */
52   human_ceiling = 0,
53   /* Round to nearest, ties to even.  */
54   human_round_to_nearest = 1,
55   /* Round to minus infinity.  */
56   human_floor = 2,
57
58   /* Group digits together, e.g. `1,000,000'.  This uses the
59      locale-defined grouping; the traditional C locale does not group,
60      so this has effect only if some other locale is in use.  */
61   human_group_digits = 4,
62
63   /* When autoscaling, suppress ".0" at end.  */
64   human_suppress_point_zero = 8,
65
66   /* Scale output and use SI-style units, ignoring the output block size.  */
67   human_autoscale = 16,
68
69   /* Prefer base 1024 to base 1000.  */
70   human_base_1024 = 32,
71
72   /* Prepend " " before unit symbol.  */
73   human_space_before_unit = 64,
74
75   /* Append SI prefix, e.g. "k" or "M".  */
76   human_SI = 128,
77
78   /* Append "B" (if base 1000) or "iB" (if base 1024) to SI prefix.  */
79   human_B = 256
80 };
81
82 char *human_readable (uintmax_t, char *, int, uintmax_t, uintmax_t);
83
84 enum strtol_error human_options (char const *, int *, uintmax_t *);
85
86 #endif /* HUMAN_H_ */