]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/gnu-sort/lib/human.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / gnu-sort / lib / human.h
1 /* human.h -- print human readable file size
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
20 /* Written by Paul Eggert and Larry McVoy.  */
21
22 #ifndef HUMAN_H_
23 # define HUMAN_H_ 1
24
25 # if HAVE_CONFIG_H
26 #  include <config.h>
27 # endif
28
29 # include <limits.h>
30 # include <stdbool.h>
31
32 # if HAVE_STDINT_H
33 #  include <stdint.h>
34 # endif
35 # if HAVE_UNISTD_H
36 #  include <unistd.h>
37 # endif
38
39 /* A conservative bound on the maximum length of a human-readable string.
40    The output can be the square of the largest uintmax_t, so double
41    its size before converting to a bound.
42    302 / 1000 is ceil (log10 (2.0)).  Add 1 for integer division truncation.
43    Also, the output can have a thousands separator between every digit,
44    so multiply by MB_LEN_MAX + 1 and then subtract MB_LEN_MAX.
45    Finally, append 3, the maximum length of a suffix.  */
46 # define LONGEST_HUMAN_READABLE \
47   ((2 * sizeof (uintmax_t) * CHAR_BIT * 302 / 1000 + 1) * (MB_LEN_MAX + 1) \
48    - MB_LEN_MAX + 3)
49
50 /* Options for human_readable.  */
51 enum
52 {
53   /* Unless otherwise specified these options may be ORed together.  */
54
55   /* The following three options are mutually exclusive.  */
56   /* Round to plus infinity (default).  */
57   human_ceiling = 0,
58   /* Round to nearest, ties to even.  */
59   human_round_to_nearest = 1,
60   /* Round to minus infinity.  */
61   human_floor = 2,
62
63   /* Group digits together, e.g. `1,000,000'.  This uses the
64      locale-defined grouping; the traditional C locale does not group,
65      so this has effect only if some other locale is in use.  */
66   human_group_digits = 4,
67
68   /* When autoscaling, suppress ".0" at end.  */
69   human_suppress_point_zero = 8,
70
71   /* Scale output and use SI-style units, ignoring the output block size.  */
72   human_autoscale = 16,
73
74   /* Prefer base 1024 to base 1000.  */
75   human_base_1024 = 32,
76
77   /* Append SI prefix, e.g. "k" or "M".  */
78   human_SI = 64,
79
80   /* Append "B" (if base 1000) or "iB" (if base 1024) to SI prefix.  */
81   human_B = 128
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_ */