Blame lib/xstrtol.h

Packit 33f14e
/* A more useful interface to strtol.
Packit 33f14e
Packit 33f14e
   Copyright (C) 1995-1996, 1998-1999, 2001-2004, 2006-2017 Free Software
Packit 33f14e
   Foundation, Inc.
Packit 33f14e
Packit 33f14e
   This program is free software: you can redistribute it and/or modify
Packit 33f14e
   it under the terms of the GNU General Public License as published by
Packit 33f14e
   the Free Software Foundation; either version 3 of the License, or
Packit 33f14e
   (at your option) any later version.
Packit 33f14e
Packit 33f14e
   This program is distributed in the hope that it will be useful,
Packit 33f14e
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 33f14e
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 33f14e
   GNU General Public License for more details.
Packit 33f14e
Packit 33f14e
   You should have received a copy of the GNU General Public License
Packit 33f14e
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 33f14e
Packit 33f14e
#ifndef XSTRTOL_H_
Packit 33f14e
# define XSTRTOL_H_ 1
Packit 33f14e
Packit 33f14e
# include <getopt.h>
Packit 33f14e
# include <inttypes.h>
Packit 33f14e
Packit 33f14e
# ifndef _STRTOL_ERROR
Packit 33f14e
enum strtol_error
Packit 33f14e
  {
Packit 33f14e
    LONGINT_OK = 0,
Packit 33f14e
Packit 33f14e
    /* These two values can be ORed together, to indicate that both
Packit 33f14e
       errors occurred.  */
Packit 33f14e
    LONGINT_OVERFLOW = 1,
Packit 33f14e
    LONGINT_INVALID_SUFFIX_CHAR = 2,
Packit 33f14e
Packit 33f14e
    LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW = (LONGINT_INVALID_SUFFIX_CHAR
Packit 33f14e
                                                 | LONGINT_OVERFLOW),
Packit 33f14e
    LONGINT_INVALID = 4
Packit 33f14e
  };
Packit 33f14e
typedef enum strtol_error strtol_error;
Packit 33f14e
# endif
Packit 33f14e
Packit 33f14e
# define _DECLARE_XSTRTOL(name, type) \
Packit 33f14e
  strtol_error name (const char *, char **, int, type *, const char *);
Packit 33f14e
_DECLARE_XSTRTOL (xstrtol, long int)
Packit 33f14e
_DECLARE_XSTRTOL (xstrtoul, unsigned long int)
Packit 33f14e
_DECLARE_XSTRTOL (xstrtoimax, intmax_t)
Packit 33f14e
_DECLARE_XSTRTOL (xstrtoumax, uintmax_t)
Packit 33f14e
Packit 33f14e
#if HAVE_LONG_LONG_INT
Packit 33f14e
_DECLARE_XSTRTOL (xstrtoll, long long int)
Packit 33f14e
_DECLARE_XSTRTOL (xstrtoull, unsigned long long int)
Packit 33f14e
#endif
Packit 33f14e
Packit 33f14e
/* Report an error for an invalid integer in an option argument.
Packit 33f14e
Packit 33f14e
   ERR is the error code returned by one of the xstrto* functions.
Packit 33f14e
Packit 33f14e
   Use OPT_IDX to decide whether to print the short option string "C"
Packit 33f14e
   or "-C" or a long option string derived from LONG_OPTION.  OPT_IDX
Packit 33f14e
   is -2 if the short option "C" was used, without any leading "-"; it
Packit 33f14e
   is -1 if the short option "-C" was used; otherwise it is an index
Packit 33f14e
   into LONG_OPTIONS, which should have a name preceded by two '-'
Packit 33f14e
   characters.
Packit 33f14e
Packit 33f14e
   ARG is the option-argument containing the integer.
Packit 33f14e
Packit 33f14e
   After reporting an error, exit with a failure status.  */
Packit 33f14e
Packit 33f14e
_Noreturn void xstrtol_fatal (enum strtol_error,
Packit 33f14e
                              int, char, struct option const *,
Packit 33f14e
                              char const *);
Packit 33f14e
Packit 33f14e
#endif /* not XSTRTOL_H_ */