197403Sobrien// -*- C++ -*- forwarding header.
297403Sobrien
3169691Skan// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
497403Sobrien// Free Software Foundation, Inc.
597403Sobrien//
697403Sobrien// This file is part of the GNU ISO C++ Library.  This library is free
797403Sobrien// software; you can redistribute it and/or modify it under the
897403Sobrien// terms of the GNU General Public License as published by the
997403Sobrien// Free Software Foundation; either version 2, or (at your option)
1097403Sobrien// any later version.
1197403Sobrien
1297403Sobrien// This library is distributed in the hope that it will be useful,
1397403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of
1497403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1597403Sobrien// GNU General Public License for more details.
1697403Sobrien
1797403Sobrien// You should have received a copy of the GNU General Public License along
1897403Sobrien// with this library; see the file COPYING.  If not, write to the Free
19169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
2097403Sobrien// USA.
2197403Sobrien
2297403Sobrien// As a special exception, you may use this file as part of a free software
2397403Sobrien// library without restriction.  Specifically, if other files instantiate
2497403Sobrien// templates or use macros or inline functions from this file, or you compile
2597403Sobrien// this file and link it with other files to produce an executable, this
2697403Sobrien// file does not by itself cause the resulting executable to be covered by
2797403Sobrien// the GNU General Public License.  This exception does not however
2897403Sobrien// invalidate any other reasons why the executable file might be covered by
2997403Sobrien// the GNU General Public License.
3097403Sobrien
31169691Skan/** @file include/cstdlib
3297403Sobrien *  This is a Standard C++ Library file.  You should @c #include this file
3397403Sobrien *  in your programs, rather than any of the "*.h" implementation files.
3497403Sobrien *
3597403Sobrien *  This is the C++ version of the Standard C Library header @c stdlib.h,
3697403Sobrien *  and its contents are (mostly) the same as that header, but are all
37169691Skan *  contained in the namespace @c std (except for names which are defined
38169691Skan *  as macros in C).
3997403Sobrien */
4097403Sobrien
41169691Skan//
42169691Skan// ISO C++ 14882: 20.4.6  C library
43169691Skan//
44169691Skan
45132720Skan#ifndef _GLIBCXX_CSTDLIB
46132720Skan#define _GLIBCXX_CSTDLIB 1
4797403Sobrien
4897403Sobrien#pragma GCC system_header
4997403Sobrien
5097403Sobrien#include <bits/c++config.h>
5197403Sobrien#include <cstddef>
5297403Sobrien
53169691Skan#if !_GLIBCXX_HOSTED
54169691Skan// The C standard does not require a freestanding implementation to
55169691Skan// provide <stdlib.h>.  However, the C++ standard does still require
56169691Skan// <cstdlib> -- but only the functionality mentioned in
57169691Skan// [lib.support.start.term].
58169691Skan
59169691Skan#define EXIT_SUCCESS 0
60169691Skan#define EXIT_FAILURE 1
61169691Skan
62169691Skan_GLIBCXX_BEGIN_NAMESPACE(std)
63169691Skan
64169691Skan  extern "C" void abort(void);
65169691Skan  extern "C" int atexit(void (*)());
66169691Skan  extern "C" void exit(int);
67169691Skan
68169691Skan_GLIBCXX_END_NAMESPACE
69169691Skan
70169691Skan#else
71169691Skan
7297403Sobrien#include <stdlib.h>
7397403Sobrien
7497403Sobrien// Get rid of those macros defined in <stdlib.h> in lieu of real functions.
7597403Sobrien#undef abort
7697403Sobrien#undef abs
7797403Sobrien#undef atexit
7897403Sobrien#undef atof
7997403Sobrien#undef atoi
8097403Sobrien#undef atol
8197403Sobrien#undef bsearch
8297403Sobrien#undef calloc
8397403Sobrien#undef div
8497403Sobrien#undef exit
8597403Sobrien#undef free
8697403Sobrien#undef getenv
8797403Sobrien#undef labs
8897403Sobrien#undef ldiv
8997403Sobrien#undef malloc
9097403Sobrien#undef mblen
9197403Sobrien#undef mbstowcs
9297403Sobrien#undef mbtowc
9397403Sobrien#undef qsort
9497403Sobrien#undef rand
9597403Sobrien#undef realloc
9697403Sobrien#undef srand
9797403Sobrien#undef strtod
9897403Sobrien#undef strtol
9997403Sobrien#undef strtoul
10097403Sobrien#undef system
10197403Sobrien#undef wcstombs
10297403Sobrien#undef wctomb
10397403Sobrien
104169691Skan_GLIBCXX_BEGIN_NAMESPACE(std)
105169691Skan
10697403Sobrien  using ::div_t;
10797403Sobrien  using ::ldiv_t;
10897403Sobrien
10997403Sobrien  using ::abort;
11097403Sobrien  using ::abs;
11197403Sobrien  using ::atexit;
11297403Sobrien  using ::atof;
11397403Sobrien  using ::atoi;
11497403Sobrien  using ::atol;
11597403Sobrien  using ::bsearch;
11697403Sobrien  using ::calloc;
11797403Sobrien  using ::div;
11897403Sobrien  using ::exit;
11997403Sobrien  using ::free;
12097403Sobrien  using ::getenv;
12197403Sobrien  using ::labs;
12297403Sobrien  using ::ldiv;
12397403Sobrien  using ::malloc;
124132720Skan#ifdef _GLIBCXX_HAVE_MBSTATE_T
12597403Sobrien  using ::mblen;
12697403Sobrien  using ::mbstowcs;
12797403Sobrien  using ::mbtowc;
128132720Skan#endif // _GLIBCXX_HAVE_MBSTATE_T
12997403Sobrien  using ::qsort;
13097403Sobrien  using ::rand;
13197403Sobrien  using ::realloc;
13297403Sobrien  using ::srand;
13397403Sobrien  using ::strtod;
13497403Sobrien  using ::strtol;
13597403Sobrien  using ::strtoul;
13697403Sobrien  using ::system;
137132720Skan#ifdef _GLIBCXX_USE_WCHAR_T
13897403Sobrien  using ::wcstombs;
13997403Sobrien  using ::wctomb;
140132720Skan#endif // _GLIBCXX_USE_WCHAR_T
14197403Sobrien
142132720Skan  inline long
14397403Sobrien  abs(long __i) { return labs(__i); }
14497403Sobrien
14597403Sobrien  inline ldiv_t
14697403Sobrien  div(long __i, long __j) { return ldiv(__i, __j); }
14797403Sobrien
148169691Skan_GLIBCXX_END_NAMESPACE
149169691Skan
150132720Skan#if _GLIBCXX_USE_C99
15197403Sobrien
15297403Sobrien#undef _Exit
15397403Sobrien#undef llabs
15497403Sobrien#undef lldiv
15597403Sobrien#undef atoll
15697403Sobrien#undef strtoll
15797403Sobrien#undef strtoull
15897403Sobrien#undef strtof
15997403Sobrien#undef strtold
16097403Sobrien
161169691Skan_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
162169691Skan
163132720Skan#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
16497403Sobrien  using ::lldiv_t;
165117397Skan#endif
166132720Skan#if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
167117397Skan  extern "C" void (_Exit)(int);
168117397Skan#endif
169132720Skan#if !_GLIBCXX_USE_C99_DYNAMIC
17097403Sobrien  using ::_Exit;
171117397Skan#endif
17297403Sobrien
173132720Skan  inline long long
17497403Sobrien  abs(long long __x) { return __x >= 0 ? __x : -__x; }
17597403Sobrien
176169691Skan#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
177169691Skan  using ::llabs;
17897403Sobrien
179132720Skan  inline lldiv_t
18097403Sobrien  div(long long __n, long long __d)
18197403Sobrien  { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
18297403Sobrien
183169691Skan  using ::lldiv;
184117397Skan#endif
18597403Sobrien
186132720Skan#if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
187117397Skan  extern "C" long long int (atoll)(const char *);
188117397Skan  extern "C" long long int
189117397Skan    (strtoll)(const char * restrict, char ** restrict, int);
190117397Skan  extern "C" unsigned long long int
191117397Skan    (strtoull)(const char * restrict, char ** restrict, int);
192117397Skan#endif
193132720Skan#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
19497403Sobrien  using ::atoll;
19597403Sobrien  using ::strtoll;
19697403Sobrien  using ::strtoull;
197117397Skan#endif
198117397Skan  using ::strtof;
199132720Skan  using ::strtold;
20097403Sobrien
201169691Skan_GLIBCXX_END_NAMESPACE
202169691Skan
203169691Skan_GLIBCXX_BEGIN_NAMESPACE(std)
204169691Skan
205132720Skan#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
206169691Skan  using ::__gnu_cxx::lldiv_t;
207117397Skan#endif
208169691Skan  using ::__gnu_cxx::_Exit;
209169691Skan  using ::__gnu_cxx::abs;
210132720Skan#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
211169691Skan  using ::__gnu_cxx::llabs;
212169691Skan  using ::__gnu_cxx::div;
213169691Skan  using ::__gnu_cxx::lldiv;
214117397Skan#endif
215169691Skan  using ::__gnu_cxx::atoll;
216169691Skan  using ::__gnu_cxx::strtof;
217169691Skan  using ::__gnu_cxx::strtoll;
218169691Skan  using ::__gnu_cxx::strtoull;
219169691Skan  using ::__gnu_cxx::strtold;
22097403Sobrien
221169691Skan_GLIBCXX_END_NAMESPACE
222169691Skan
223169691Skan#endif // _GLIBCXX_USE_C99
224169691Skan
225169691Skan#endif // !_GLIBCXX_HOSTED
226169691Skan
227132720Skan#endif
228