Blame lib/human.h

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