Blame lib/human.h

Packit 8f70b4
/* human.h -- print human readable file size
Packit 8f70b4
Packit 8f70b4
   Copyright (C) 1996-2007, 2009-2018 Free Software Foundation, Inc.
Packit 8f70b4
Packit 8f70b4
   This program is free software: you can redistribute it and/or modify
Packit 8f70b4
   it under the terms of the GNU General Public License as published by
Packit 8f70b4
   the Free Software Foundation; either version 3 of the License, or
Packit 8f70b4
   (at your option) any later version.
Packit 8f70b4
Packit 8f70b4
   This program is distributed in the hope that it will be useful,
Packit 8f70b4
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8f70b4
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 8f70b4
   GNU General Public License for more details.
Packit 8f70b4
Packit 8f70b4
   You should have received a copy of the GNU General Public License
Packit 8f70b4
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit 8f70b4
Packit 8f70b4
/* Written by Paul Eggert and Larry McVoy.  */
Packit 8f70b4
Packit 8f70b4
#ifndef HUMAN_H_
Packit 8f70b4
# define HUMAN_H_ 1
Packit 8f70b4
Packit 8f70b4
# include <limits.h>
Packit 8f70b4
# include <stdbool.h>
Packit 8f70b4
# include <stdint.h>
Packit 8f70b4
# include <unistd.h>
Packit 8f70b4
Packit 8f70b4
# include <xstrtol.h>
Packit 8f70b4
Packit 8f70b4
/* A conservative bound on the maximum length of a human-readable string.
Packit 8f70b4
   The output can be the square of the largest uintmax_t, so double
Packit 8f70b4
   its size before converting to a bound.
Packit 8f70b4
   log10 (2.0) < 146/485.  Add 1 for integer division truncation.
Packit 8f70b4
   Also, the output can have a thousands separator between every digit,
Packit 8f70b4
   so multiply by MB_LEN_MAX + 1 and then subtract MB_LEN_MAX.
Packit 8f70b4
   Append 1 for a space before the suffix.
Packit 8f70b4
   Finally, append 3, the maximum length of a suffix.  */
Packit 8f70b4
# define LONGEST_HUMAN_READABLE \
Packit 8f70b4
  ((2 * sizeof (uintmax_t) * CHAR_BIT * 146 / 485 + 1) * (MB_LEN_MAX + 1) \
Packit 8f70b4
   - MB_LEN_MAX + 1 + 3)
Packit 8f70b4
Packit 8f70b4
/* Options for human_readable.  */
Packit 8f70b4
enum
Packit 8f70b4
{
Packit 8f70b4
  /* Unless otherwise specified these options may be ORed together.  */
Packit 8f70b4
Packit 8f70b4
  /* The following three options are mutually exclusive.  */
Packit 8f70b4
  /* Round to plus infinity (default).  */
Packit 8f70b4
  human_ceiling = 0,
Packit 8f70b4
  /* Round to nearest, ties to even.  */
Packit 8f70b4
  human_round_to_nearest = 1,
Packit 8f70b4
  /* Round to minus infinity.  */
Packit 8f70b4
  human_floor = 2,
Packit 8f70b4
Packit 8f70b4
  /* Group digits together, e.g. "1,000,000".  This uses the
Packit 8f70b4
     locale-defined grouping; the traditional C locale does not group,
Packit 8f70b4
     so this has effect only if some other locale is in use.  */
Packit 8f70b4
  human_group_digits = 4,
Packit 8f70b4
Packit 8f70b4
  /* When autoscaling, suppress ".0" at end.  */
Packit 8f70b4
  human_suppress_point_zero = 8,
Packit 8f70b4
Packit 8f70b4
  /* Scale output and use SI-style units, ignoring the output block size.  */
Packit 8f70b4
  human_autoscale = 16,
Packit 8f70b4
Packit 8f70b4
  /* Prefer base 1024 to base 1000.  */
Packit 8f70b4
  human_base_1024 = 32,
Packit 8f70b4
Packit 8f70b4
  /* Prepend " " before unit symbol.  */
Packit 8f70b4
  human_space_before_unit = 64,
Packit 8f70b4
Packit 8f70b4
  /* Append SI prefix, e.g. "k" or "M".  */
Packit 8f70b4
  human_SI = 128,
Packit 8f70b4
Packit 8f70b4
  /* Append "B" (if base 1000) or "iB" (if base 1024) to SI prefix.  */
Packit 8f70b4
  human_B = 256
Packit 8f70b4
};
Packit 8f70b4
Packit 8f70b4
char *human_readable (uintmax_t, char *, int, uintmax_t, uintmax_t);
Packit 8f70b4
Packit 8f70b4
enum strtol_error human_options (char const *, int *, uintmax_t *);
Packit 8f70b4
Packit 8f70b4
#endif /* HUMAN_H_ */