Blame lib/strtoimax.c

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