]> git.ipfire.org Git - thirdparty/glibc.git/blame - stdlib/strtol.c
Use locale_t, not __locale_t, throughout glibc
[thirdparty/glibc.git] / stdlib / strtol.c
CommitLineData
2f6d1f1b 1/* Convert string representation of a number into an integer value.
bfff8b1b 2 Copyright (C) 1991-2017 Free Software Foundation, Inc.
f0e44959
UD
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
f0e44959
UD
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 13 Lesser General Public License for more details.
f0e44959 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
f0e44959 18
ccadf7b5
UD
19#include <stdlib.h>
20#include <wchar.h>
21#include <locale/localeinfo.h>
f0bf9cb9 22
f0bf9cb9 23#ifndef UNSIGNED
e09675dd
JM
24# define UNSIGNED 0
25# define INT LONG int
f0bf9cb9 26#else
e09675dd 27# define INT unsigned LONG int
28f540f4
RM
28#endif
29
ccadf7b5
UD
30#if UNSIGNED
31# ifdef USE_WIDE_CHAR
32# ifdef QUAD
33# define strtol wcstoull
34# define __strtol_l __wcstoull_l
75cd5204 35# else
ccadf7b5
UD
36# define strtol wcstoul
37# define __strtol_l __wcstoul_l
75cd5204
RM
38# endif
39# else
ccadf7b5
UD
40# ifdef QUAD
41# define strtol strtoull
42# define __strtol_l __strtoull_l
75cd5204 43# else
ccadf7b5
UD
44# define strtol strtoul
45# define __strtol_l __strtoul_l
75cd5204
RM
46# endif
47# endif
48#else
ccadf7b5
UD
49# ifdef USE_WIDE_CHAR
50# ifdef QUAD
51# define strtol wcstoll
52# define __strtol_l __wcstoll_l
75cd5204 53# else
ccadf7b5
UD
54# define strtol wcstol
55# define __strtol_l __wcstol_l
75cd5204
RM
56# endif
57# else
ccadf7b5
UD
58# ifdef QUAD
59# define strtol strtoll
60# define __strtol_l __strtoll_l
75cd5204
RM
61# endif
62# endif
63#endif
64
ccadf7b5 65
2f6d1f1b 66/* If QUAD is defined, we are defining `strtoll' or `strtoull',
28f540f4
RM
67 operating on `long long int's. */
68#ifdef QUAD
e09675dd 69# define LONG long long
28f540f4 70#else
e09675dd 71# define LONG long
0501d603
UD
72#endif
73
74
75cd5204 75#ifdef USE_WIDE_CHAR
75cd5204 76# define STRING_TYPE wchar_t
28f540f4 77#else
ccadf7b5 78# define STRING_TYPE char
28f540f4
RM
79#endif
80
ccadf7b5
UD
81
82#define INTERNAL(X) INTERNAL1(X)
83#define INTERNAL1(X) __##X##_internal
f0bf9cb9 84
2a1cfd94
JM
85#define SYM__(X) SYM__1 (X)
86#define SYM__1(X) __ ## X
87#define __strtol SYM__ (strtol)
88
f0bf9cb9 89
ccadf7b5 90extern INT INTERNAL (__strtol_l) (const STRING_TYPE *, STRING_TYPE **, int,
af85385f 91 int, locale_t);
0501d603 92
f0bf9cb9
RM
93
94INT
80d9be81
JM
95INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr,
96 int base, int group)
28f540f4 97{
ccadf7b5 98 return INTERNAL (__strtol_l) (nptr, endptr, base, group, _NL_CURRENT_LOCALE);
28f540f4 99}
509d1b68 100libc_hidden_def (INTERNAL (strtol))
f0e44959
UD
101
102
f0bf9cb9 103INT
bf438382 104__strtol (const STRING_TYPE *nptr, STRING_TYPE **endptr, int base)
f0bf9cb9 105{
ccadf7b5 106 return INTERNAL (__strtol_l) (nptr, endptr, base, 0, _NL_CURRENT_LOCALE);
f0bf9cb9 107}
2a1cfd94
JM
108weak_alias (__strtol, strtol)
109libc_hidden_weak (strtol)