Blame lib/xstrtol.h

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