Debian Codegraph @

libstdc++-v3/include/c_std/cstdlib

raw
1 // -*- C++ -*- forwarding header.
2
3 // Copyright (C) 1997-2025 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24
25 /** @file include/cstdlib
26 * This is a Standard C++ Library file. You should @c #include this file
27 * in your programs, rather than any of the @a *.h implementation files.
28 *
29 * This is the C++ version of the Standard C Library header @c stdlib.h,
30 * and its contents are (mostly) the same as that header, but are all
31 * contained in the namespace @c std (except for names which are defined
32 * as macros in C).
33 */
34
35 //
36 // ISO C++ 14882: 20.4.6 C library
37 //
38
39 #ifndef _GLIBCXX_CSTDLIB
40 #define _GLIBCXX_CSTDLIB 1
41
42 #ifdef _GLIBCXX_SYSHDR
43 #pragma GCC system_header
44 #endif
45
46 #include <bits/c++config.h>
47
48 #if !_GLIBCXX_HOSTED
49 // The C standard does not require a freestanding implementation to
50 // provide <stdlib.h>. However, the C++ standard does still require
51 // <cstdlib> -- but only the functionality mentioned in
52 // [lib.support.start.term].
53
54 #define EXIT_SUCCESS 0
55 #define EXIT_FAILURE 1
56
57 namespace std
58 {
59 extern "C" void abort(void) throw () _GLIBCXX_NORETURN;
60 extern "C" int atexit(void (*)(void)) throw ();
61 extern "C" void exit(int) throw () _GLIBCXX_NORETURN;
62 #if __cplusplus >= 201103L
63 # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
64 extern "C" int at_quick_exit(void (*)(void)) throw ();
65 # endif
66 # ifdef _GLIBCXX_HAVE_QUICK_EXIT
67 extern "C" void quick_exit(int) throw() _GLIBCXX_NORETURN;
68 # endif
69 #endif
70 } // namespace
71
72 #else
73
74 #include <stdlib.h>
75
76 // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
77 #undef abort
78 #undef abs
79 #undef atexit
80 #if __cplusplus >= 201103L
81 # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
82 # undef at_quick_exit
83 # endif
84 #endif
85 #undef atof
86 #undef atoi
87 #undef atol
88 #undef bsearch
89 #undef calloc
90 #undef div
91 #undef exit
92 #undef free
93 #undef getenv
94 #undef labs
95 #undef ldiv
96 #undef malloc
97 #undef mblen
98 #undef mbstowcs
99 #undef mbtowc
100 #undef qsort
101 #if __cplusplus >= 201103L
102 # ifdef _GLIBCXX_HAVE_QUICK_EXIT
103 # undef quick_exit
104 # endif
105 #endif
106 #undef rand
107 #undef realloc
108 #undef srand
109 #undef strtod
110 #undef strtol
111 #undef strtoul
112 #undef system
113 #undef wcstombs
114 #undef wctomb
115
116 namespace std _GLIBCXX_VISIBILITY(default)
117 {
118 _GLIBCXX_BEGIN_NAMESPACE_VERSION
119
120 using ::div_t;
121 using ::ldiv_t;
122
123 using ::abort;
124 using ::abs;
125 using ::atexit;
126 #if __cplusplus >= 201103L
127 # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
128 using ::at_quick_exit;
129 # endif
130 #endif
131 using ::atof;
132 using ::atoi;
133 using ::atol;
134 using ::bsearch;
135 using ::calloc;
136 using ::div;
137 using ::exit;
138 using ::free;
139 using ::getenv;
140 using ::labs;
141 using ::ldiv;
142 using ::malloc;
143 #ifdef _GLIBCXX_HAVE_MBSTATE_T
144 using ::mblen;
145 using ::mbstowcs;
146 using ::mbtowc;
147 #endif // _GLIBCXX_HAVE_MBSTATE_T
148 using ::qsort;
149 #if __cplusplus >= 201103L
150 # ifdef _GLIBCXX_HAVE_QUICK_EXIT
151 using ::quick_exit;
152 # endif
153 #endif
154 using ::rand;
155 using ::realloc;
156 using ::srand;
157 using ::strtod;
158 using ::strtol;
159 using ::strtoul;
160 using ::system;
161 #ifdef _GLIBCXX_USE_WCHAR_T
162 using ::wcstombs;
163 using ::wctomb;
164 #endif // _GLIBCXX_USE_WCHAR_T
165
166 inline long
167 abs(long __i) { return __builtin_labs(__i); }
168
169 #ifdef _GLIBCXX_USE_LONG_LONG
170 inline long long
171 abs(long long __x) { return __builtin_llabs (__x); }
172 #endif
173
174 #if defined(__GLIBCXX_TYPE_INT_N_0)
175 inline __GLIBCXX_TYPE_INT_N_0
176 abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
177 #endif
178 #if defined(__GLIBCXX_TYPE_INT_N_1)
179 inline __GLIBCXX_TYPE_INT_N_1
180 abs(__GLIBCXX_TYPE_INT_N_1 __x) { return __x >= 0 ? __x : -__x; }
181 #endif
182 #if defined(__GLIBCXX_TYPE_INT_N_2)
183 inline __GLIBCXX_TYPE_INT_N_2
184 abs(__GLIBCXX_TYPE_INT_N_2 __x) { return __x >= 0 ? __x : -__x; }
185 #endif
186 #if defined(__GLIBCXX_TYPE_INT_N_3)
187 inline __GLIBCXX_TYPE_INT_N_3
188 abs(__GLIBCXX_TYPE_INT_N_3 __x) { return __x >= 0 ? __x : -__x; }
189 #endif
190
191 inline ldiv_t
192 div(long __i, long __j) { return ldiv(__i, __j); }
193
194 _GLIBCXX_END_NAMESPACE_VERSION
195 } // namespace
196
197 #if _GLIBCXX_USE_C99_STDLIB
198
199 #undef _Exit
200 #undef llabs
201 #undef lldiv
202 #undef atoll
203 #undef strtoll
204 #undef strtoull
205 #undef strtof
206 #undef strtold
207
208 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
209 {
210 _GLIBCXX_BEGIN_NAMESPACE_VERSION
211
212 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
213 using ::lldiv_t;
214 #endif
215 #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
216 extern "C" void (_Exit)(int) throw () _GLIBCXX_NORETURN;
217 #endif
218 #if !_GLIBCXX_USE_C99_DYNAMIC
219 using ::_Exit;
220 #endif
221
222 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
223 using ::llabs;
224
225 inline lldiv_t
226 div(long long __n, long long __d)
227 { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
228
229 using ::lldiv;
230 #endif
231
232 #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
233 extern "C" long long int (atoll)(const char *) throw ();
234 extern "C" long long int
235 (strtoll)(const char * __restrict, char ** __restrict, int) throw ();
236 extern "C" unsigned long long int
237 (strtoull)(const char * __restrict, char ** __restrict, int) throw ();
238 #endif
239 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
240 using ::atoll;
241 using ::strtoll;
242 using ::strtoull;
243 #endif
244 using ::strtof;
245 using ::strtold;
246
247 _GLIBCXX_END_NAMESPACE_VERSION
248 } // namespace __gnu_cxx
249
250 namespace std
251 {
252 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
253 using ::__gnu_cxx::lldiv_t;
254 #endif
255 using ::__gnu_cxx::_Exit;
256 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
257 using ::__gnu_cxx::llabs;
258 using ::__gnu_cxx::div;
259 using ::__gnu_cxx::lldiv;
260 #endif
261 using ::__gnu_cxx::atoll;
262 using ::__gnu_cxx::strtof;
263 using ::__gnu_cxx::strtoll;
264 using ::__gnu_cxx::strtoull;
265 using ::__gnu_cxx::strtold;
266 } // namespace std
267
268 #endif // _GLIBCXX_USE_C99_STDLIB
269
270 #endif // !_GLIBCXX_HOSTED
271
272 #endif