xref: /openbsd-src/gnu/gcc/libstdc++-v3/include/c_std/std_cstdlib.h (revision 6570f8749eb85e92180967d0b1ee9911b31bfb63)
1404b540aSrobert // -*- C++ -*- forwarding header.
2404b540aSrobert 
3404b540aSrobert // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4404b540aSrobert // Free Software Foundation, Inc.
5404b540aSrobert //
6404b540aSrobert // This file is part of the GNU ISO C++ Library.  This library is free
7404b540aSrobert // software; you can redistribute it and/or modify it under the
8404b540aSrobert // terms of the GNU General Public License as published by the
9404b540aSrobert // Free Software Foundation; either version 2, or (at your option)
10404b540aSrobert // any later version.
11404b540aSrobert 
12404b540aSrobert // This library is distributed in the hope that it will be useful,
13404b540aSrobert // but WITHOUT ANY WARRANTY; without even the implied warranty of
14404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15404b540aSrobert // GNU General Public License for more details.
16404b540aSrobert 
17404b540aSrobert // You should have received a copy of the GNU General Public License along
18404b540aSrobert // with this library; see the file COPYING.  If not, write to the Free
19404b540aSrobert // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20404b540aSrobert // USA.
21404b540aSrobert 
22404b540aSrobert // As a special exception, you may use this file as part of a free software
23404b540aSrobert // library without restriction.  Specifically, if other files instantiate
24404b540aSrobert // templates or use macros or inline functions from this file, or you compile
25404b540aSrobert // this file and link it with other files to produce an executable, this
26404b540aSrobert // file does not by itself cause the resulting executable to be covered by
27404b540aSrobert // the GNU General Public License.  This exception does not however
28404b540aSrobert // invalidate any other reasons why the executable file might be covered by
29404b540aSrobert // the GNU General Public License.
30404b540aSrobert 
31404b540aSrobert /** @file include/cstdlib
32404b540aSrobert  *  This is a Standard C++ Library file.  You should @c #include this file
33404b540aSrobert  *  in your programs, rather than any of the "*.h" implementation files.
34404b540aSrobert  *
35404b540aSrobert  *  This is the C++ version of the Standard C Library header @c stdlib.h,
36404b540aSrobert  *  and its contents are (mostly) the same as that header, but are all
37404b540aSrobert  *  contained in the namespace @c std (except for names which are defined
38404b540aSrobert  *  as macros in C).
39404b540aSrobert  */
40404b540aSrobert 
41404b540aSrobert //
42404b540aSrobert // ISO C++ 14882: 20.4.6  C library
43404b540aSrobert //
44404b540aSrobert 
45404b540aSrobert #ifndef _GLIBCXX_CSTDLIB
46404b540aSrobert #define _GLIBCXX_CSTDLIB 1
47404b540aSrobert 
48404b540aSrobert #pragma GCC system_header
49404b540aSrobert 
50404b540aSrobert #include <bits/c++config.h>
51404b540aSrobert #include <cstddef>
52404b540aSrobert 
53404b540aSrobert #if !_GLIBCXX_HOSTED
54404b540aSrobert // The C standard does not require a freestanding implementation to
55404b540aSrobert // provide <stdlib.h>.  However, the C++ standard does still require
56404b540aSrobert // <cstdlib> -- but only the functionality mentioned in
57404b540aSrobert // [lib.support.start.term].
58404b540aSrobert 
59404b540aSrobert #define EXIT_SUCCESS 0
60404b540aSrobert #define EXIT_FAILURE 1
61404b540aSrobert 
62404b540aSrobert _GLIBCXX_BEGIN_NAMESPACE(std)
63404b540aSrobert 
64404b540aSrobert   extern "C" void abort(void);
65404b540aSrobert   extern "C" int atexit(void (*)());
66404b540aSrobert   extern "C" void exit(int);
67404b540aSrobert 
68404b540aSrobert _GLIBCXX_END_NAMESPACE
69404b540aSrobert 
70404b540aSrobert #else
71404b540aSrobert 
72404b540aSrobert #include <stdlib.h>
73404b540aSrobert 
74404b540aSrobert // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
75404b540aSrobert #undef abort
76404b540aSrobert #undef abs
77404b540aSrobert #undef atexit
78404b540aSrobert #undef atof
79404b540aSrobert #undef atoi
80404b540aSrobert #undef atol
81404b540aSrobert #undef bsearch
82404b540aSrobert #undef calloc
83404b540aSrobert #undef div
84404b540aSrobert #undef exit
85404b540aSrobert #undef free
86404b540aSrobert #undef getenv
87404b540aSrobert #undef labs
88404b540aSrobert #undef ldiv
89404b540aSrobert #undef malloc
90404b540aSrobert #undef mblen
91404b540aSrobert #undef mbstowcs
92404b540aSrobert #undef mbtowc
93404b540aSrobert #undef qsort
94404b540aSrobert #undef rand
95404b540aSrobert #undef realloc
96404b540aSrobert #undef srand
97404b540aSrobert #undef strtod
98404b540aSrobert #undef strtol
99404b540aSrobert #undef strtoul
100404b540aSrobert #undef system
101404b540aSrobert #undef wcstombs
102404b540aSrobert #undef wctomb
103404b540aSrobert 
104404b540aSrobert _GLIBCXX_BEGIN_NAMESPACE(std)
105404b540aSrobert 
106404b540aSrobert   using ::div_t;
107404b540aSrobert   using ::ldiv_t;
108404b540aSrobert 
109404b540aSrobert   using ::abort;
110404b540aSrobert   using ::abs;
111404b540aSrobert   using ::atexit;
112404b540aSrobert   using ::atof;
113404b540aSrobert   using ::atoi;
114404b540aSrobert   using ::atol;
115404b540aSrobert   using ::bsearch;
116404b540aSrobert   using ::calloc;
117404b540aSrobert   using ::div;
118404b540aSrobert   using ::exit;
119404b540aSrobert   using ::free;
120404b540aSrobert   using ::getenv;
121404b540aSrobert   using ::labs;
122404b540aSrobert   using ::ldiv;
123404b540aSrobert   using ::malloc;
124404b540aSrobert #ifdef _GLIBCXX_HAVE_MBSTATE_T
125404b540aSrobert   using ::mblen;
126404b540aSrobert   using ::mbstowcs;
127404b540aSrobert   using ::mbtowc;
128404b540aSrobert #endif // _GLIBCXX_HAVE_MBSTATE_T
129404b540aSrobert   using ::qsort;
130404b540aSrobert   using ::rand;
131404b540aSrobert   using ::realloc;
132404b540aSrobert   using ::srand;
133404b540aSrobert   using ::strtod;
134404b540aSrobert   using ::strtol;
135404b540aSrobert   using ::strtoul;
136404b540aSrobert   using ::system;
137404b540aSrobert #ifdef _GLIBCXX_USE_WCHAR_T
138404b540aSrobert   using ::wcstombs;
139404b540aSrobert   using ::wctomb;
140404b540aSrobert #endif // _GLIBCXX_USE_WCHAR_T
141404b540aSrobert 
142404b540aSrobert   inline long
143404b540aSrobert   abs(long __i) { return labs(__i); }
144404b540aSrobert 
145404b540aSrobert   inline ldiv_t
146404b540aSrobert   div(long __i, long __j) { return ldiv(__i, __j); }
147404b540aSrobert 
148404b540aSrobert _GLIBCXX_END_NAMESPACE
149404b540aSrobert 
150404b540aSrobert #if _GLIBCXX_USE_C99
151404b540aSrobert 
152404b540aSrobert #undef _Exit
153404b540aSrobert #undef llabs
154404b540aSrobert #undef lldiv
155404b540aSrobert #undef atoll
156404b540aSrobert #undef strtoll
157404b540aSrobert #undef strtoull
158404b540aSrobert #undef strtof
159404b540aSrobert #undef strtold
160404b540aSrobert 
161404b540aSrobert _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
162404b540aSrobert 
163404b540aSrobert #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
164404b540aSrobert   using ::lldiv_t;
165404b540aSrobert #endif
166404b540aSrobert #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
167404b540aSrobert   extern "C" void (_Exit)(int);
168404b540aSrobert #endif
169404b540aSrobert #if !_GLIBCXX_USE_C99_DYNAMIC
170404b540aSrobert   using ::_Exit;
171404b540aSrobert #endif
172404b540aSrobert 
173404b540aSrobert   inline long long
174404b540aSrobert   abs(long long __x) { return __x >= 0 ? __x : -__x; }
175404b540aSrobert 
176404b540aSrobert #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
177404b540aSrobert   using ::llabs;
178404b540aSrobert 
179404b540aSrobert   inline lldiv_t
180404b540aSrobert   div(long long __n, long long __d)
181404b540aSrobert   { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
182404b540aSrobert 
183404b540aSrobert   using ::lldiv;
184404b540aSrobert #endif
185404b540aSrobert 
186404b540aSrobert #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
187404b540aSrobert   extern "C" long long int (atoll)(const char *);
188404b540aSrobert   extern "C" long long int
189*6570f874Spascal     (strtoll)(const char * __restrict, char ** __restrict, int);
190404b540aSrobert   extern "C" unsigned long long int
191*6570f874Spascal     (strtoull)(const char * __restrict, char ** __restrict, int);
192404b540aSrobert #endif
193404b540aSrobert #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
194404b540aSrobert   using ::atoll;
195404b540aSrobert   using ::strtoll;
196404b540aSrobert   using ::strtoull;
197404b540aSrobert #endif
198404b540aSrobert   using ::strtof;
199404b540aSrobert   using ::strtold;
200404b540aSrobert 
201404b540aSrobert _GLIBCXX_END_NAMESPACE
202404b540aSrobert 
203404b540aSrobert _GLIBCXX_BEGIN_NAMESPACE(std)
204404b540aSrobert 
205404b540aSrobert #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
206404b540aSrobert   using ::__gnu_cxx::lldiv_t;
207404b540aSrobert #endif
208404b540aSrobert   using ::__gnu_cxx::_Exit;
209404b540aSrobert   using ::__gnu_cxx::abs;
210404b540aSrobert #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
211404b540aSrobert   using ::__gnu_cxx::llabs;
212404b540aSrobert   using ::__gnu_cxx::div;
213404b540aSrobert   using ::__gnu_cxx::lldiv;
214404b540aSrobert #endif
215404b540aSrobert   using ::__gnu_cxx::atoll;
216404b540aSrobert   using ::__gnu_cxx::strtof;
217404b540aSrobert   using ::__gnu_cxx::strtoll;
218404b540aSrobert   using ::__gnu_cxx::strtoull;
219404b540aSrobert   using ::__gnu_cxx::strtold;
220404b540aSrobert 
221404b540aSrobert _GLIBCXX_END_NAMESPACE
222404b540aSrobert 
223404b540aSrobert #endif // _GLIBCXX_USE_C99
224404b540aSrobert 
225404b540aSrobert #endif // !_GLIBCXX_HOSTED
226404b540aSrobert 
227404b540aSrobert #endif
228