Blame lib/strtoimax.c

Packit Service a2489d
/* Convert string representation of a number into an intmax_t value.
Packit Service a2489d
Packit Service a2489d
   Copyright (C) 1999, 2001-2004, 2006, 2009-2018 Free Software Foundation,
Packit Service a2489d
   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. */
Packit Service a2489d
Packit Service a2489d
#include <config.h>
Packit Service a2489d
Packit Service a2489d
/* Verify interface.  */
Packit Service a2489d
#include <inttypes.h>
Packit Service a2489d
Packit Service a2489d
#include <stdlib.h>
Packit Service a2489d
Packit Service a2489d
#include "verify.h"
Packit Service a2489d
Packit Service a2489d
#ifdef UNSIGNED
Packit Service a2489d
# if HAVE_UNSIGNED_LONG_LONG_INT
Packit Service a2489d
#  ifndef HAVE_DECL_STRTOULL
Packit Service a2489d
"this configure-time declaration test was not run"
Packit Service a2489d
#  endif
Packit Service a2489d
#  if !HAVE_DECL_STRTOULL
Packit Service a2489d
unsigned long long int strtoull (char const *, char **, int);
Packit Service a2489d
#  endif
Packit Service a2489d
# endif
Packit Service a2489d
Packit Service a2489d
#else
Packit Service a2489d
Packit Service a2489d
# if HAVE_LONG_LONG_INT
Packit Service a2489d
#  ifndef HAVE_DECL_STRTOLL
Packit Service a2489d
"this configure-time declaration test was not run"
Packit Service a2489d
#  endif
Packit Service a2489d
#  if !HAVE_DECL_STRTOLL
Packit Service a2489d
long long int strtoll (char const *, char **, int);
Packit Service a2489d
#  endif
Packit Service a2489d
# endif
Packit Service a2489d
#endif
Packit Service a2489d
Packit Service a2489d
#ifdef UNSIGNED
Packit Service a2489d
# define Have_long_long HAVE_UNSIGNED_LONG_LONG_INT
Packit Service a2489d
# define Int uintmax_t
Packit Service a2489d
# define Strtoimax strtoumax
Packit Service a2489d
# define Strtol strtoul
Packit Service a2489d
# define Strtoll strtoull
Packit Service a2489d
# define Unsigned unsigned
Packit Service a2489d
#else
Packit Service a2489d
# define Have_long_long HAVE_LONG_LONG_INT
Packit Service a2489d
# define Int intmax_t
Packit Service a2489d
# define Strtoimax strtoimax
Packit Service a2489d
# define Strtol strtol
Packit Service a2489d
# define Strtoll strtoll
Packit Service a2489d
# define Unsigned
Packit Service a2489d
#endif
Packit Service a2489d
Packit Service a2489d
Int
Packit Service a2489d
Strtoimax (char const *ptr, char **endptr, int base)
Packit Service a2489d
{
Packit Service a2489d
#if Have_long_long
Packit Service a2489d
  verify (sizeof (Int) == sizeof (Unsigned long int)
Packit Service a2489d
          || sizeof (Int) == sizeof (Unsigned long long int));
Packit Service a2489d
Packit Service a2489d
  if (sizeof (Int) != sizeof (Unsigned long int))
Packit Service a2489d
    return Strtoll (ptr, endptr, base);
Packit Service a2489d
#else
Packit Service a2489d
  verify (sizeof (Int) == sizeof (Unsigned long int));
Packit Service a2489d
#endif
Packit Service a2489d
Packit Service a2489d
  return Strtol (ptr, endptr, base);
Packit Service a2489d
}