Blame lib/strtoimax.c

Packit Service fdd496
/* Convert string representation of a number into an intmax_t value.
Packit Service fdd496
Packit Service fdd496
   Copyright (C) 1999, 2001-2004, 2006, 2009-2017 Free Software Foundation,
Packit Service fdd496
   Inc.
Packit Service fdd496
Packit Service fdd496
   This program is free software: you can redistribute it and/or modify
Packit Service fdd496
   it under the terms of the GNU General Public License as published by
Packit Service fdd496
   the Free Software Foundation; either version 3 of the License, or
Packit Service fdd496
   (at your option) any later version.
Packit Service fdd496
Packit Service fdd496
   This program is distributed in the hope that it will be useful,
Packit Service fdd496
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fdd496
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service fdd496
   GNU General Public License for more details.
Packit Service fdd496
Packit Service fdd496
   You should have received a copy of the GNU General Public License
Packit Service fdd496
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Service fdd496
Packit Service fdd496
/* Written by Paul Eggert. */
Packit Service fdd496
Packit Service fdd496
#include <config.h>
Packit Service fdd496
Packit Service fdd496
/* Verify interface.  */
Packit Service fdd496
#include <inttypes.h>
Packit Service fdd496
Packit Service fdd496
#include <stdlib.h>
Packit Service fdd496
Packit Service fdd496
#include "verify.h"
Packit Service fdd496
Packit Service fdd496
#ifdef UNSIGNED
Packit Service fdd496
# if HAVE_UNSIGNED_LONG_LONG_INT
Packit Service fdd496
#  ifndef HAVE_DECL_STRTOULL
Packit Service fdd496
"this configure-time declaration test was not run"
Packit Service fdd496
#  endif
Packit Service fdd496
#  if !HAVE_DECL_STRTOULL
Packit Service fdd496
unsigned long long int strtoull (char const *, char **, int);
Packit Service fdd496
#  endif
Packit Service fdd496
# endif
Packit Service fdd496
Packit Service fdd496
#else
Packit Service fdd496
Packit Service fdd496
# if HAVE_LONG_LONG_INT
Packit Service fdd496
#  ifndef HAVE_DECL_STRTOLL
Packit Service fdd496
"this configure-time declaration test was not run"
Packit Service fdd496
#  endif
Packit Service fdd496
#  if !HAVE_DECL_STRTOLL
Packit Service fdd496
long long int strtoll (char const *, char **, int);
Packit Service fdd496
#  endif
Packit Service fdd496
# endif
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
#ifdef UNSIGNED
Packit Service fdd496
# define Have_long_long HAVE_UNSIGNED_LONG_LONG_INT
Packit Service fdd496
# define Int uintmax_t
Packit Service fdd496
# define Strtoimax strtoumax
Packit Service fdd496
# define Strtol strtoul
Packit Service fdd496
# define Strtoll strtoull
Packit Service fdd496
# define Unsigned unsigned
Packit Service fdd496
#else
Packit Service fdd496
# define Have_long_long HAVE_LONG_LONG_INT
Packit Service fdd496
# define Int intmax_t
Packit Service fdd496
# define Strtoimax strtoimax
Packit Service fdd496
# define Strtol strtol
Packit Service fdd496
# define Strtoll strtoll
Packit Service fdd496
# define Unsigned
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
Int
Packit Service fdd496
Strtoimax (char const *ptr, char **endptr, int base)
Packit Service fdd496
{
Packit Service fdd496
#if Have_long_long
Packit Service fdd496
  verify (sizeof (Int) == sizeof (Unsigned long int)
Packit Service fdd496
          || sizeof (Int) == sizeof (Unsigned long long int));
Packit Service fdd496
Packit Service fdd496
  if (sizeof (Int) != sizeof (Unsigned long int))
Packit Service fdd496
    return Strtoll (ptr, endptr, base);
Packit Service fdd496
#else
Packit Service fdd496
  verify (sizeof (Int) == sizeof (Unsigned long int));
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
  return Strtol (ptr, endptr, base);
Packit Service fdd496
}