da95c0fe56c09b12ef3a9d8ee3e20661ca229deb
[gcc.git] / libstdc++-v3 / include / c_global / cstdlib
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 _GLIBCXX_BEGIN_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
63 _GLIBCXX_END_NAMESPACE
64
65 #else
66
67 #include <stdlib.h>
68
69 // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
70 #undef abort
71 #undef abs
72 #undef atexit
73 #undef atof
74 #undef atoi
75 #undef atol
76 #undef bsearch
77 #undef calloc
78 #undef div
79 #undef exit
80 #undef free
81 #undef getenv
82 #undef labs
83 #undef ldiv
84 #undef malloc
85 #undef mblen
86 #undef mbstowcs
87 #undef mbtowc
88 #undef qsort
89 #undef rand
90 #undef realloc
91 #undef srand
92 #undef strtod
93 #undef strtol
94 #undef strtoul
95 #undef system
96 #undef wcstombs
97 #undef wctomb
98
99 _GLIBCXX_BEGIN_NAMESPACE(std)
100
101 using ::div_t;
102 using ::ldiv_t;
103
104 using ::abort;
105 using ::abs;
106 using ::atexit;
107 using ::atof;
108 using ::atoi;
109 using ::atol;
110 using ::bsearch;
111 using ::calloc;
112 using ::div;
113 using ::exit;
114 using ::free;
115 using ::getenv;
116 using ::labs;
117 using ::ldiv;
118 using ::malloc;
119 #ifdef _GLIBCXX_HAVE_MBSTATE_T
120 using ::mblen;
121 using ::mbstowcs;
122 using ::mbtowc;
123 #endif // _GLIBCXX_HAVE_MBSTATE_T
124 using ::qsort;
125 using ::rand;
126 using ::realloc;
127 using ::srand;
128 using ::strtod;
129 using ::strtol;
130 using ::strtoul;
131 using ::system;
132 #ifdef _GLIBCXX_USE_WCHAR_T
133 using ::wcstombs;
134 using ::wctomb;
135 #endif // _GLIBCXX_USE_WCHAR_T
136
137 inline long
138 abs(long __i) { return labs(__i); }
139
140 inline ldiv_t
141 div(long __i, long __j) { return ldiv(__i, __j); }
142
143 _GLIBCXX_END_NAMESPACE
144
145 #if _GLIBCXX_USE_C99
146
147 #undef _Exit
148 #undef llabs
149 #undef lldiv
150 #undef atoll
151 #undef strtoll
152 #undef strtoull
153 #undef strtof
154 #undef strtold
155
156 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
157
158 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
159 using ::lldiv_t;
160 #endif
161 #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
162 extern "C" void (_Exit)(int) throw () _GLIBCXX_NORETURN;
163 #endif
164 #if !_GLIBCXX_USE_C99_DYNAMIC
165 using ::_Exit;
166 #endif
167
168 inline long long
169 abs(long long __x) { return __x >= 0 ? __x : -__x; }
170
171 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
172 using ::llabs;
173
174 inline lldiv_t
175 div(long long __n, long long __d)
176 { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
177
178 using ::lldiv;
179 #endif
180
181 #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
182 extern "C" long long int (atoll)(const char *) throw ();
183 extern "C" long long int
184 (strtoll)(const char * restrict, char ** restrict, int) throw ();
185 extern "C" unsigned long long int
186 (strtoull)(const char * restrict, char ** restrict, int) throw ();
187 #endif
188 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
189 using ::atoll;
190 using ::strtoll;
191 using ::strtoull;
192 #endif
193 using ::strtof;
194 using ::strtold;
195
196 _GLIBCXX_END_NAMESPACE
197
198 _GLIBCXX_BEGIN_NAMESPACE(std)
199
200 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
201 using ::__gnu_cxx::lldiv_t;
202 #endif
203 using ::__gnu_cxx::_Exit;
204 using ::__gnu_cxx::abs;
205 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
206 using ::__gnu_cxx::llabs;
207 using ::__gnu_cxx::div;
208 using ::__gnu_cxx::lldiv;
209 #endif
210 using ::__gnu_cxx::atoll;
211 using ::__gnu_cxx::strtof;
212 using ::__gnu_cxx::strtoll;
213 using ::__gnu_cxx::strtoull;
214 using ::__gnu_cxx::strtold;
215
216 _GLIBCXX_END_NAMESPACE
217
218 #endif // _GLIBCXX_USE_C99
219
220 #ifdef __GXX_EXPERIMENTAL_CXX0X__
221 # if defined(_GLIBCXX_INCLUDE_AS_TR1)
222 # error C++0x header cannot be included from TR1 header
223 # endif
224 # if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
225 # include <tr1_impl/cstdlib>
226 # else
227 # define _GLIBCXX_INCLUDE_AS_CXX0X
228 # define _GLIBCXX_BEGIN_NAMESPACE_TR1
229 # define _GLIBCXX_END_NAMESPACE_TR1
230 # define _GLIBCXX_TR1
231 # include <tr1_impl/cstdlib>
232 # undef _GLIBCXX_TR1
233 # undef _GLIBCXX_END_NAMESPACE_TR1
234 # undef _GLIBCXX_BEGIN_NAMESPACE_TR1
235 # undef _GLIBCXX_INCLUDE_AS_CXX0X
236 # endif
237 #endif
238
239 #endif // !_GLIBCXX_HOSTED
240
241 #endif