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