root/maint/gnulib/lib/human.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


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

/* [previous][next][first][last][top][bottom][index][help] */