Blame lib/strtoimax.c

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