libstdc++
cstdlib
Go to the documentation of this file.
1 // -*- C++ -*- forwarding header.
2 
3 // Copyright (C) 1997-2020 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 #pragma GCC system_header
40 
41 #include <bits/c++config.h>
42 
43 #ifndef _GLIBCXX_CSTDLIB
44 #define _GLIBCXX_CSTDLIB 1
45 
46 #if !_GLIBCXX_HOSTED
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].
51 
52 #define EXIT_SUCCESS 0
53 #define EXIT_FAILURE 1
54 
55 namespace std
56 {
57  extern "C" void abort(void) throw () _GLIBCXX_NORETURN;
58  extern "C" int atexit(void (*)(void)) throw ();
59  extern "C" void exit(int) throw () _GLIBCXX_NORETURN;
60 #if __cplusplus >= 201103L
61 # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
62  extern "C" int at_quick_exit(void (*)(void)) throw ();
63 # endif
64 # ifdef _GLIBCXX_HAVE_QUICK_EXIT
65  extern "C" void quick_exit(int) throw() _GLIBCXX_NORETURN;
66 # endif
67 #endif
68 } // namespace std
69 
70 #else
71 
72 // Need to ensure this finds the C library's <stdlib.h> not a libstdc++
73 // wrapper that might already be installed later in the include search path.
74 #define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
75 #include_next <stdlib.h>
76 #undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS
77 #include <bits/std_abs.h>
78 
79 // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
80 #undef abort
81 #if __cplusplus >= 201703L && defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)
82 # undef aligned_alloc
83 #endif
84 #undef atexit
85 #if __cplusplus >= 201103L
86 # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
87 # undef at_quick_exit
88 # endif
89 #endif
90 #undef atof
91 #undef atoi
92 #undef atol
93 #undef bsearch
94 #undef calloc
95 #undef div
96 #undef exit
97 #undef free
98 #undef getenv
99 #undef labs
100 #undef ldiv
101 #undef malloc
102 #undef mblen
103 #undef mbstowcs
104 #undef mbtowc
105 #undef qsort
106 #if __cplusplus >= 201103L
107 # ifdef _GLIBCXX_HAVE_QUICK_EXIT
108 # undef quick_exit
109 # endif
110 #endif
111 #undef rand
112 #undef realloc
113 #undef srand
114 #undef strtod
115 #undef strtol
116 #undef strtoul
117 #undef system
118 #undef wcstombs
119 #undef wctomb
120 
121 extern "C++"
122 {
123 namespace std _GLIBCXX_VISIBILITY(default)
124 {
125 _GLIBCXX_BEGIN_NAMESPACE_VERSION
126 
127  using ::div_t;
128  using ::ldiv_t;
129 
130  using ::abort;
131 #if __cplusplus >= 201703L && defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)
132  using ::aligned_alloc;
133 #endif
134  using ::atexit;
135 #if __cplusplus >= 201103L
136 # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
137  using ::at_quick_exit;
138 # endif
139 #endif
140  using ::atof;
141  using ::atoi;
142  using ::atol;
143  using ::bsearch;
144  using ::calloc;
145  using ::div;
146  using ::exit;
147  using ::free;
148  using ::getenv;
149  using ::labs;
150  using ::ldiv;
151  using ::malloc;
152 #ifdef _GLIBCXX_HAVE_MBSTATE_T
153  using ::mblen;
154  using ::mbstowcs;
155  using ::mbtowc;
156 #endif // _GLIBCXX_HAVE_MBSTATE_T
157  using ::qsort;
158 #if __cplusplus >= 201103L
159 # ifdef _GLIBCXX_HAVE_QUICK_EXIT
160  using ::quick_exit;
161 # endif
162 #endif
163  using ::rand;
164  using ::realloc;
165  using ::srand;
166  using ::strtod;
167  using ::strtol;
168  using ::strtoul;
169  using ::system;
170 #ifdef _GLIBCXX_USE_WCHAR_T
171  using ::wcstombs;
172  using ::wctomb;
173 #endif // _GLIBCXX_USE_WCHAR_T
174 
175 #ifndef __CORRECT_ISO_CPP_STDLIB_H_PROTO
176  inline ldiv_t
177  div(long __i, long __j) { return ldiv(__i, __j); }
178 #endif
179 
180 
181 _GLIBCXX_END_NAMESPACE_VERSION
182 } // namespace
183 
184 #if _GLIBCXX_USE_C99_STDLIB
185 
186 #undef _Exit
187 #undef llabs
188 #undef lldiv
189 #undef atoll
190 #undef strtoll
191 #undef strtoull
192 #undef strtof
193 #undef strtold
194 
195 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
196 {
197 _GLIBCXX_BEGIN_NAMESPACE_VERSION
198 
199 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
200  using ::lldiv_t;
201 #endif
202 #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
203  extern "C" void (_Exit)(int) throw () _GLIBCXX_NORETURN;
204 #endif
205 #if !_GLIBCXX_USE_C99_DYNAMIC
206  using ::_Exit;
207 #endif
208 
209 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
210  using ::llabs;
211 
212  inline lldiv_t
213  div(long long __n, long long __d)
214  { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
215 
216  using ::lldiv;
217 #endif
218 
219 #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
220  extern "C" long long int (atoll)(const char *) throw ();
221  extern "C" long long int
222  (strtoll)(const char * __restrict, char ** __restrict, int) throw ();
223  extern "C" unsigned long long int
224  (strtoull)(const char * __restrict, char ** __restrict, int) throw ();
225 #endif
226 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
227  using ::atoll;
228  using ::strtoll;
229  using ::strtoull;
230 #endif
231  using ::strtof;
232  using ::strtold;
233 
234 _GLIBCXX_END_NAMESPACE_VERSION
235 } // namespace __gnu_cxx
236 
237 namespace std
238 {
239 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
240  using ::__gnu_cxx::lldiv_t;
241 #endif
242  using ::__gnu_cxx::_Exit;
243 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
244  using ::__gnu_cxx::llabs;
245  using ::__gnu_cxx::div;
246  using ::__gnu_cxx::lldiv;
247 #endif
248  using ::__gnu_cxx::atoll;
249  using ::__gnu_cxx::strtof;
250  using ::__gnu_cxx::strtoll;
251  using ::__gnu_cxx::strtoull;
252  using ::__gnu_cxx::strtold;
253 } // namespace std
254 
255 #endif // _GLIBCXX_USE_C99_STDLIB
256 
257 } // extern "C++"
258 
259 #endif // !_GLIBCXX_HOSTED
260 
261 #endif