]> git.ipfire.org Git - thirdparty/glibc.git/blame - stdlib/strtol.c
Refer to C23 in place of C2X in glibc
[thirdparty/glibc.git] / stdlib / strtol.c
CommitLineData
2f6d1f1b 1/* Convert string representation of a number into an integer value.
dff8da6b 2 Copyright (C) 1991-2024 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 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
f0e44959 18
64924422 19#include <features.h>
42cc619d
JM
20#undef __GLIBC_USE_C23_STRTOL
21#define __GLIBC_USE_C23_STRTOL 0
ccadf7b5
UD
22#include <stdlib.h>
23#include <wchar.h>
24#include <locale/localeinfo.h>
f0bf9cb9 25
f0bf9cb9 26#ifndef UNSIGNED
e09675dd
JM
27# define UNSIGNED 0
28# define INT LONG int
f0bf9cb9 29#else
e09675dd 30# define INT unsigned LONG int
28f540f4
RM
31#endif
32
ccadf7b5
UD
33#if UNSIGNED
34# ifdef USE_WIDE_CHAR
35# ifdef QUAD
36# define strtol wcstoull
37# define __strtol_l __wcstoull_l
64924422 38# define __isoc23_strtol __isoc23_wcstoull
75cd5204 39# else
ccadf7b5
UD
40# define strtol wcstoul
41# define __strtol_l __wcstoul_l
64924422 42# define __isoc23_strtol __isoc23_wcstoul
75cd5204
RM
43# endif
44# else
ccadf7b5
UD
45# ifdef QUAD
46# define strtol strtoull
47# define __strtol_l __strtoull_l
64924422 48# define __isoc23_strtol __isoc23_strtoull
75cd5204 49# else
ccadf7b5
UD
50# define strtol strtoul
51# define __strtol_l __strtoul_l
64924422 52# define __isoc23_strtol __isoc23_strtoul
75cd5204
RM
53# endif
54# endif
55#else
ccadf7b5
UD
56# ifdef USE_WIDE_CHAR
57# ifdef QUAD
58# define strtol wcstoll
59# define __strtol_l __wcstoll_l
64924422 60# define __isoc23_strtol __isoc23_wcstoll
75cd5204 61# else
ccadf7b5
UD
62# define strtol wcstol
63# define __strtol_l __wcstol_l
64924422 64# define __isoc23_strtol __isoc23_wcstol
75cd5204
RM
65# endif
66# else
ccadf7b5
UD
67# ifdef QUAD
68# define strtol strtoll
69# define __strtol_l __strtoll_l
64924422 70# define __isoc23_strtol __isoc23_strtoll
75cd5204
RM
71# endif
72# endif
73#endif
74
ccadf7b5 75
2f6d1f1b 76/* If QUAD is defined, we are defining `strtoll' or `strtoull',
28f540f4
RM
77 operating on `long long int's. */
78#ifdef QUAD
e09675dd 79# define LONG long long
28f540f4 80#else
e09675dd 81# define LONG long
0501d603
UD
82#endif
83
84
75cd5204 85#ifdef USE_WIDE_CHAR
75cd5204 86# define STRING_TYPE wchar_t
28f540f4 87#else
ccadf7b5 88# define STRING_TYPE char
28f540f4
RM
89#endif
90
ccadf7b5
UD
91
92#define INTERNAL(X) INTERNAL1(X)
93#define INTERNAL1(X) __##X##_internal
f0bf9cb9 94
2a1cfd94
JM
95#define SYM__(X) SYM__1 (X)
96#define SYM__1(X) __ ## X
97#define __strtol SYM__ (strtol)
98
f0bf9cb9 99
ccadf7b5 100extern INT INTERNAL (__strtol_l) (const STRING_TYPE *, STRING_TYPE **, int,
64924422 101 int, bool, locale_t);
0501d603 102
f0bf9cb9
RM
103
104INT
80d9be81
JM
105INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr,
106 int base, int group)
28f540f4 107{
64924422
JM
108 return INTERNAL (__strtol_l) (nptr, endptr, base, group, false,
109 _NL_CURRENT_LOCALE);
28f540f4 110}
509d1b68 111libc_hidden_def (INTERNAL (strtol))
f0e44959
UD
112
113
f0bf9cb9 114INT
bf438382 115__strtol (const STRING_TYPE *nptr, STRING_TYPE **endptr, int base)
f0bf9cb9 116{
64924422
JM
117 return INTERNAL (__strtol_l) (nptr, endptr, base, 0, false,
118 _NL_CURRENT_LOCALE);
f0bf9cb9 119}
2a1cfd94
JM
120weak_alias (__strtol, strtol)
121libc_hidden_weak (strtol)
64924422
JM
122
123INT
124__isoc23_strtol (const STRING_TYPE *nptr, STRING_TYPE **endptr, int base)
125{
126 return INTERNAL (__strtol_l) (nptr, endptr, base, 0, true,
127 _NL_CURRENT_LOCALE);
128}
129libc_hidden_def (__isoc23_strtol)