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