1997-02-25 05:18:05 +00:00
|
|
|
/* Convert string representation of a number into an integer value.
|
2018-01-01 00:32:25 +00:00
|
|
|
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
|
|
|
|
1995-03-16 05:32:45 +00:00
|
|
|
#ifndef UNSIGNED
|
1995-07-17 13:34:12 +00:00
|
|
|
# define UNSIGNED 0
|
|
|
|
|
# define INT LONG int
|
1995-03-16 05:32:45 +00:00
|
|
|
#else
|
1995-07-17 13:34:12 +00:00
|
|
|
# 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
|
1996-05-01 13:55:18 +00:00
|
|
|
# else
|
2004-03-14 21:12:06 +00:00
|
|
|
# define strtol wcstoul
|
|
|
|
|
# define __strtol_l __wcstoul_l
|
1996-05-01 13:55:18 +00:00
|
|
|
# endif
|
|
|
|
|
# else
|
2004-03-14 21:12:06 +00:00
|
|
|
# ifdef QUAD
|
|
|
|
|
# define strtol strtoull
|
|
|
|
|
# define __strtol_l __strtoull_l
|
1996-05-01 13:55:18 +00:00
|
|
|
# else
|
2004-03-14 21:12:06 +00:00
|
|
|
# define strtol strtoul
|
|
|
|
|
# define __strtol_l __strtoul_l
|
1996-05-01 13:55:18 +00:00
|
|
|
# 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
|
1996-05-01 13:55:18 +00:00
|
|
|
# else
|
2004-03-14 21:12:06 +00:00
|
|
|
# define strtol wcstol
|
|
|
|
|
# define __strtol_l __wcstol_l
|
1996-05-01 13:55:18 +00:00
|
|
|
# endif
|
|
|
|
|
# else
|
2004-03-14 21:12:06 +00:00
|
|
|
# ifdef QUAD
|
|
|
|
|
# define strtol strtoll
|
|
|
|
|
# define __strtol_l __strtoll_l
|
1996-05-01 13:55:18 +00:00
|
|
|
# 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
|
1995-07-17 13:34:12 +00:00
|
|
|
# define LONG long long
|
1995-02-18 01:27:10 +00:00
|
|
|
#else
|
1995-07-17 13:34:12 +00:00
|
|
|
# define LONG long
|
1995-02-18 01:27:10 +00:00
|
|
|
#endif
|
1995-07-17 13:34:12 +00:00
|
|
|
|
1997-05-24 02:30:09 +00:00
|
|
|
|
1996-05-01 13:55:18 +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
|
1995-07-17 13:34:12 +00:00
|
|
|
#endif
|
1995-03-16 05:32:45 +00:00
|
|
|
|
|
|
|
|
|
2004-03-14 21:12:06 +00:00
|
|
|
#define INTERNAL(X) INTERNAL1(X)
|
|
|
|
|
#define INTERNAL1(X) __##X##_internal
|
|
|
|
|
|
2014-11-13 19:50:55 +00:00
|
|
|
#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,
|
2017-06-20 09:26:43 -04:00
|
|
|
int, locale_t);
|
1997-05-24 02:30:09 +00:00
|
|
|
|
1995-03-16 05:32:45 +00:00
|
|
|
|
|
|
|
|
INT
|
2015-10-20 21:27:22 +00:00
|
|
|
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
|
|
|
}
|
2002-08-04 01:29:29 +00:00
|
|
|
libc_hidden_def (INTERNAL (strtol))
|
1996-11-02 01:28:01 +00:00
|
|
|
|
|
|
|
|
|
1995-03-16 05:32:45 +00:00
|
|
|
INT
|
2014-11-13 21:37:53 +00:00
|
|
|
__strtol (const STRING_TYPE *nptr, STRING_TYPE **endptr, int base)
|
1995-03-16 05:32:45 +00:00
|
|
|
{
|
2004-03-14 21:12:06 +00:00
|
|
|
return INTERNAL (__strtol_l) (nptr, endptr, base, 0, _NL_CURRENT_LOCALE);
|
1995-03-16 05:32:45 +00:00
|
|
|
}
|
2014-11-13 19:50:55 +00:00
|
|
|
weak_alias (__strtol, strtol)
|
|
|
|
|
libc_hidden_weak (strtol)
|