syslog: Improve fortify with clang
[glibc.git] / stdlib / strtol.c
blob5373f0c025dc47fd36d2aebd22e64e4fe6c12e28
1 /* Convert string representation of a number into an integer value.
2 Copyright (C) 1991-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
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.
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
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <features.h>
20 #undef __GLIBC_USE_C23_STRTOL
21 #define __GLIBC_USE_C23_STRTOL 0
22 #include <stdlib.h>
23 #include <wchar.h>
24 #include <locale/localeinfo.h>
26 #ifndef UNSIGNED
27 # define UNSIGNED 0
28 # define INT LONG int
29 #else
30 # define INT unsigned LONG int
31 #endif
33 #if UNSIGNED
34 # ifdef USE_WIDE_CHAR
35 # ifdef QUAD
36 # define strtol wcstoull
37 # define __strtol_l __wcstoull_l
38 # define __isoc23_strtol __isoc23_wcstoull
39 # else
40 # define strtol wcstoul
41 # define __strtol_l __wcstoul_l
42 # define __isoc23_strtol __isoc23_wcstoul
43 # endif
44 # else
45 # ifdef QUAD
46 # define strtol strtoull
47 # define __strtol_l __strtoull_l
48 # define __isoc23_strtol __isoc23_strtoull
49 # else
50 # define strtol strtoul
51 # define __strtol_l __strtoul_l
52 # define __isoc23_strtol __isoc23_strtoul
53 # endif
54 # endif
55 #else
56 # ifdef USE_WIDE_CHAR
57 # ifdef QUAD
58 # define strtol wcstoll
59 # define __strtol_l __wcstoll_l
60 # define __isoc23_strtol __isoc23_wcstoll
61 # else
62 # define strtol wcstol
63 # define __strtol_l __wcstol_l
64 # define __isoc23_strtol __isoc23_wcstol
65 # endif
66 # else
67 # ifdef QUAD
68 # define strtol strtoll
69 # define __strtol_l __strtoll_l
70 # define __isoc23_strtol __isoc23_strtoll
71 # endif
72 # endif
73 #endif
76 /* If QUAD is defined, we are defining `strtoll' or `strtoull',
77 operating on `long long int's. */
78 #ifdef QUAD
79 # define LONG long long
80 #else
81 # define LONG long
82 #endif
85 #ifdef USE_WIDE_CHAR
86 # define STRING_TYPE wchar_t
87 #else
88 # define STRING_TYPE char
89 #endif
92 #define INTERNAL(X) INTERNAL1(X)
93 #define INTERNAL1(X) __##X##_internal
95 #define SYM__(X) SYM__1 (X)
96 #define SYM__1(X) __ ## X
97 #define __strtol SYM__ (strtol)
100 extern INT INTERNAL (__strtol_l) (const STRING_TYPE *, STRING_TYPE **, int,
101 int, bool, locale_t);
105 INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr,
106 int base, int group)
108 return INTERNAL (__strtol_l) (nptr, endptr, base, group, false,
109 _NL_CURRENT_LOCALE);
111 libc_hidden_def (INTERNAL (strtol))
115 __strtol (const STRING_TYPE *nptr, STRING_TYPE **endptr, int base)
117 return INTERNAL (__strtol_l) (nptr, endptr, base, 0, false,
118 _NL_CURRENT_LOCALE);
120 weak_alias (__strtol, strtol)
121 libc_hidden_weak (strtol)
124 __isoc23_strtol (const STRING_TYPE *nptr, STRING_TYPE **endptr, int base)
126 return INTERNAL (__strtol_l) (nptr, endptr, base, 0, true,
127 _NL_CURRENT_LOCALE);
129 libc_hidden_def (__isoc23_strtol)