Files
glibc/stdlib/strtol.c
T

110 lines
2.6 KiB
C
Raw Normal View History

1997-02-25 05:18:05 +00:00
/* Convert string representation of a number into an integer value.
Copyright (C) 1991-2018 Free Software Foundation, Inc.
1996-11-02 01:28:01 +00:00
This file is part of the GNU C Library.
1995-02-18 01:27:10 +00:00
1996-11-02 01:28:01 +00:00
The GNU C Library is free software; you can redistribute it and/or
2001-07-06 04:58:11 +00:00
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
1995-02-18 01:27:10 +00:00
1996-11-02 01:28:01 +00:00
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2001-07-06 04:58:11 +00:00
Lesser General Public License for more details.
1995-02-18 01:27:10 +00:00
2001-07-06 04:58:11 +00:00
You should have received a copy of the GNU Lesser General Public
2012-02-09 23:18:22 +00:00
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
1995-02-18 01:27:10 +00:00
2004-03-14 21:12:06 +00:00
#include <stdlib.h>
#include <wchar.h>
#include <locale/localeinfo.h>
1995-02-18 01:27:10 +00:00
#ifndef UNSIGNED
# define UNSIGNED 0
# define INT LONG int
#else
# define INT unsigned LONG int
1995-02-18 01:27:10 +00:00
#endif
2004-03-14 21:12:06 +00:00
#if UNSIGNED
# ifdef USE_WIDE_CHAR
# ifdef QUAD
# define strtol wcstoull
# define __strtol_l __wcstoull_l
# else
2004-03-14 21:12:06 +00:00
# define strtol wcstoul
# define __strtol_l __wcstoul_l
# endif
# else
2004-03-14 21:12:06 +00:00
# ifdef QUAD
# define strtol strtoull
# define __strtol_l __strtoull_l
# else
2004-03-14 21:12:06 +00:00
# define strtol strtoul
# define __strtol_l __strtoul_l
# endif
# endif
#else
2004-03-14 21:12:06 +00:00
# ifdef USE_WIDE_CHAR
# ifdef QUAD
# define strtol wcstoll
# define __strtol_l __wcstoll_l
# else
2004-03-14 21:12:06 +00:00
# define strtol wcstol
# define __strtol_l __wcstol_l
# endif
# else
2004-03-14 21:12:06 +00:00
# ifdef QUAD
# define strtol strtoll
# define __strtol_l __strtoll_l
# endif
# endif
#endif
2004-03-14 21:12:06 +00:00
1997-02-25 05:18:05 +00:00
/* If QUAD is defined, we are defining `strtoll' or `strtoull',
1995-02-18 01:27:10 +00:00
operating on `long long int's. */
#ifdef QUAD
# define LONG long long
1995-02-18 01:27:10 +00:00
#else
# define LONG long
1995-02-18 01:27:10 +00:00
#endif
1997-05-24 02:30:09 +00:00
#ifdef USE_WIDE_CHAR
# define STRING_TYPE wchar_t
1995-02-18 01:27:10 +00:00
#else
2004-03-14 21:12:06 +00:00
# define STRING_TYPE char
#endif
2004-03-14 21:12:06 +00:00
#define INTERNAL(X) INTERNAL1(X)
#define INTERNAL1(X) __##X##_internal
#define SYM__(X) SYM__1 (X)
#define SYM__1(X) __ ## X
#define __strtol SYM__ (strtol)
2004-03-14 21:12:06 +00:00
extern INT INTERNAL (__strtol_l) (const STRING_TYPE *, STRING_TYPE **, int,
int, locale_t);
1997-05-24 02:30:09 +00:00
INT
INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr,
int base, int group)
1995-02-18 01:27:10 +00:00
{
2004-03-14 21:12:06 +00:00
return INTERNAL (__strtol_l) (nptr, endptr, base, group, _NL_CURRENT_LOCALE);
1995-02-18 01:27:10 +00:00
}
libc_hidden_def (INTERNAL (strtol))
1996-11-02 01:28:01 +00:00
INT
2014-11-13 21:37:53 +00:00
__strtol (const STRING_TYPE *nptr, STRING_TYPE **endptr, int base)
{
2004-03-14 21:12:06 +00:00
return INTERNAL (__strtol_l) (nptr, endptr, base, 0, _NL_CURRENT_LOCALE);
}
weak_alias (__strtol, strtol)
libc_hidden_weak (strtol)