1 // -*- C++ -*- forwarding header.
3 // Copyright (C) 1997-2024 Free Software Foundation, Inc.
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)
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.
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.
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/>.
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.
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
36 // ISO C++ 14882: 20.4.6 C library
39 #pragma GCC system_header
41 #include <bits/c++config.h>
43 #ifndef _GLIBCXX_CSTDLIB
44 #define _GLIBCXX_CSTDLIB 1
47 // The C standard does not require a freestanding implementation to
48 // provide <stdlib.h>. However, the C++ standard does still require
49 // <cstdlib> -- but only the functionality mentioned in
50 // [lib.support.start.term].
52 #define EXIT_SUCCESS 0
53 #define EXIT_FAILURE 1
58 extern "C" void abort(void) _GLIBCXX_NOTHROW _GLIBCXX_NORETURN;
59 extern "C" int atexit(void (*)(void)) _GLIBCXX_NOTHROW;
60 extern "C" void exit(int) _GLIBCXX_NOTHROW _GLIBCXX_NORETURN;
61 #if __cplusplus >= 201103L
62 # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
63 extern "C" int at_quick_exit(void (*)(void)) _GLIBCXX_NOTHROW;
65 # ifdef _GLIBCXX_HAVE_QUICK_EXIT
66 extern "C" void quick_exit(int) _GLIBCXX_NOTHROW _GLIBCXX_NORETURN;
68 #if _GLIBCXX_USE_C99_STDLIB
69 extern "C" void _Exit(int) _GLIBCXX_NOTHROW _GLIBCXX_NORETURN;
76 // Need to ensure this finds the C library's <stdlib.h> not a libstdc++
77 // wrapper that might already be installed later in the include search path.
78 #define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
79 #include_next <stdlib.h>
80 #undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS
81 #include <bits/std_abs.h>
83 // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
85 #if __cplusplus >= 201703L && defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)
89 #if __cplusplus >= 201103L
90 # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
110 #if __cplusplus >= 201103L
111 # ifdef _GLIBCXX_HAVE_QUICK_EXIT
127 namespace std _GLIBCXX_VISIBILITY(default)
129 _GLIBCXX_BEGIN_NAMESPACE_VERSION
135 #if __cplusplus >= 201703L && defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)
136 using ::aligned_alloc;
139 #if __cplusplus >= 201103L
140 # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
141 using ::at_quick_exit;
156 #ifdef _GLIBCXX_HAVE_MBSTATE_T
160 #endif // _GLIBCXX_HAVE_MBSTATE_T
162 #if __cplusplus >= 201103L
163 # ifdef _GLIBCXX_HAVE_QUICK_EXIT
174 #ifdef _GLIBCXX_USE_WCHAR_T
177 #endif // _GLIBCXX_USE_WCHAR_T
179 #ifndef __CORRECT_ISO_CPP_STDLIB_H_PROTO
181 div(long __i, long __j) _GLIBCXX_NOTHROW { return ldiv(__i, __j); }
185 _GLIBCXX_END_NAMESPACE_VERSION
188 #if _GLIBCXX_USE_C99_STDLIB
199 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
201 _GLIBCXX_BEGIN_NAMESPACE_VERSION
203 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
206 #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
207 extern "C" void (_Exit)(int) _GLIBCXX_NOTHROW _GLIBCXX_NORETURN;
209 #if !_GLIBCXX_USE_C99_DYNAMIC
213 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
217 div(long long __n, long long __d)
218 { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
223 #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
224 extern "C" long long int (atoll)(const char *) _GLIBCXX_NOTHROW;
225 extern "C" long long int
226 (strtoll)(const char * __restrict, char ** __restrict, int) _GLIBCXX_NOTHROW;
227 extern "C" unsigned long long int
228 (strtoull)(const char * __restrict, char ** __restrict, int) _GLIBCXX_NOTHROW;
230 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
238 _GLIBCXX_END_NAMESPACE_VERSION
239 } // namespace __gnu_cxx
243 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
244 using ::__gnu_cxx::lldiv_t;
246 using ::__gnu_cxx::_Exit;
247 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
248 using ::__gnu_cxx::llabs;
249 using ::__gnu_cxx::div;
250 using ::__gnu_cxx::lldiv;
252 using ::__gnu_cxx::atoll;
253 using ::__gnu_cxx::strtof;
254 using ::__gnu_cxx::strtoll;
255 using ::__gnu_cxx::strtoull;
256 using ::__gnu_cxx::strtold;
259 #else // ! _GLIBCXX_USE_C99_STDLIB
261 // We also check for strtof and strtold separately from _GLIBCXX_USE_C99_STDLIB
263 #if _GLIBCXX_HAVE_STRTOF
265 namespace std { using ::strtof; }
268 #if _GLIBCXX_HAVE_STRTOLD
270 namespace std { using ::strtold; }
273 #endif // _GLIBCXX_USE_C99_STDLIB
277 #endif // !_GLIBCXX_HOSTED