Blame lib/xstrtol.h

Packit 8f70b4
/* A more useful interface to strtol.
Packit 8f70b4
Packit 8f70b4
   Copyright (C) 1995-1996, 1998-1999, 2001-2004, 2006-2018 Free Software
Packit 8f70b4
   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
#ifndef XSTRTOL_H_
Packit 8f70b4
# define XSTRTOL_H_ 1
Packit 8f70b4
Packit 8f70b4
# include <getopt.h>
Packit 8f70b4
# include <inttypes.h>
Packit 8f70b4
Packit 8f70b4
# ifndef _STRTOL_ERROR
Packit 8f70b4
enum strtol_error
Packit 8f70b4
  {
Packit 8f70b4
    LONGINT_OK = 0,
Packit 8f70b4
Packit 8f70b4
    /* These two values can be ORed together, to indicate that both
Packit 8f70b4
       errors occurred.  */
Packit 8f70b4
    LONGINT_OVERFLOW = 1,
Packit 8f70b4
    LONGINT_INVALID_SUFFIX_CHAR = 2,
Packit 8f70b4
Packit 8f70b4
    LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW = (LONGINT_INVALID_SUFFIX_CHAR
Packit 8f70b4
                                                 | LONGINT_OVERFLOW),
Packit 8f70b4
    LONGINT_INVALID = 4
Packit 8f70b4
  };
Packit 8f70b4
typedef enum strtol_error strtol_error;
Packit 8f70b4
# endif
Packit 8f70b4
Packit 8f70b4
# define _DECLARE_XSTRTOL(name, type) \
Packit 8f70b4
  strtol_error name (const char *, char **, int, type *, const char *);
Packit 8f70b4
_DECLARE_XSTRTOL (xstrtol, long int)
Packit 8f70b4
_DECLARE_XSTRTOL (xstrtoul, unsigned long int)
Packit 8f70b4
_DECLARE_XSTRTOL (xstrtoimax, intmax_t)
Packit 8f70b4
_DECLARE_XSTRTOL (xstrtoumax, uintmax_t)
Packit 8f70b4
Packit 8f70b4
#if HAVE_LONG_LONG_INT
Packit 8f70b4
_DECLARE_XSTRTOL (xstrtoll, long long int)
Packit 8f70b4
_DECLARE_XSTRTOL (xstrtoull, unsigned long long int)
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
/* Report an error for an invalid integer in an option argument.
Packit 8f70b4
Packit 8f70b4
   ERR is the error code returned by one of the xstrto* functions.
Packit 8f70b4
Packit 8f70b4
   Use OPT_IDX to decide whether to print the short option string "C"
Packit 8f70b4
   or "-C" or a long option string derived from LONG_OPTION.  OPT_IDX
Packit 8f70b4
   is -2 if the short option "C" was used, without any leading "-"; it
Packit 8f70b4
   is -1 if the short option "-C" was used; otherwise it is an index
Packit 8f70b4
   into LONG_OPTIONS, which should have a name preceded by two '-'
Packit 8f70b4
   characters.
Packit 8f70b4
Packit 8f70b4
   ARG is the option-argument containing the integer.
Packit 8f70b4
Packit 8f70b4
   After reporting an error, exit with a failure status.  */
Packit 8f70b4
Packit 8f70b4
_Noreturn void xstrtol_fatal (enum strtol_error,
Packit 8f70b4
                              int, char, struct option const *,
Packit 8f70b4
                              char const *);
Packit 8f70b4
Packit 8f70b4
#endif /* not XSTRTOL_H_ */