libstdc++
cstdlib
Go to the documentation of this file.
00001 // -*- C++ -*- forwarding header.
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
00004 // 2006, 2007, 2008, 2009, 2010, 2011
00005 // Free Software Foundation, Inc.
00006 //
00007 // This file is part of the GNU ISO C++ Library.  This library is free
00008 // software; you can redistribute it and/or modify it under the
00009 // terms of the GNU General Public License as published by the
00010 // Free Software Foundation; either version 3, or (at your option)
00011 // any later version.
00012 
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 
00018 // Under Section 7 of GPL version 3, you are granted additional
00019 // permissions described in the GCC Runtime Library Exception, version
00020 // 3.1, as published by the Free Software Foundation.
00021 
00022 // You should have received a copy of the GNU General Public License and
00023 // a copy of the GCC Runtime Library Exception along with this program;
00024 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00025 // <http://www.gnu.org/licenses/>.
00026 
00027 /** @file include/cstdlib
00028  *  This is a Standard C++ Library file.  You should @c \#include this file
00029  *  in your programs, rather than any of the @a *.h implementation files.
00030  *
00031  *  This is the C++ version of the Standard C Library header @c stdlib.h,
00032  *  and its contents are (mostly) the same as that header, but are all
00033  *  contained in the namespace @c std (except for names which are defined
00034  *  as macros in C).
00035  */
00036 
00037 //
00038 // ISO C++ 14882: 20.4.6  C library
00039 //
00040 
00041 #pragma GCC system_header
00042 
00043 #include <bits/c++config.h>
00044 
00045 #ifndef _GLIBCXX_CSTDLIB
00046 #define _GLIBCXX_CSTDLIB 1
00047 
00048 #if !_GLIBCXX_HOSTED
00049 // The C standard does not require a freestanding implementation to
00050 // provide <stdlib.h>.  However, the C++ standard does still require
00051 // <cstdlib> -- but only the functionality mentioned in
00052 // [lib.support.start.term].
00053 
00054 #define EXIT_SUCCESS 0
00055 #define EXIT_FAILURE 1
00056 
00057 namespace std
00058 {
00059   extern "C" void abort(void) throw () _GLIBCXX_NORETURN;
00060   extern "C" int atexit(void (*)()) throw ();
00061   extern "C" void exit(int) throw () _GLIBCXX_NORETURN;
00062 } // namespace std
00063 
00064 #else
00065 
00066 #include <stdlib.h>
00067 
00068 // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
00069 #undef abort
00070 #undef abs
00071 #undef atexit
00072 #undef atof
00073 #undef atoi
00074 #undef atol
00075 #undef bsearch
00076 #undef calloc
00077 #undef div
00078 #undef exit
00079 #undef free
00080 #undef getenv
00081 #undef labs
00082 #undef ldiv
00083 #undef malloc
00084 #undef mblen
00085 #undef mbstowcs
00086 #undef mbtowc
00087 #undef qsort
00088 #undef rand
00089 #undef realloc
00090 #undef srand
00091 #undef strtod
00092 #undef strtol
00093 #undef strtoul
00094 #undef system
00095 #undef wcstombs
00096 #undef wctomb
00097 
00098 namespace std _GLIBCXX_VISIBILITY(default)
00099 {
00100 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00101 
00102   using ::div_t;
00103   using ::ldiv_t;
00104 
00105   using ::abort;
00106   using ::abs;
00107   using ::atexit;
00108   using ::atof;
00109   using ::atoi;
00110   using ::atol;
00111   using ::bsearch;
00112   using ::calloc;
00113   using ::div;
00114   using ::exit;
00115   using ::free;
00116   using ::getenv;
00117   using ::labs;
00118   using ::ldiv;
00119   using ::malloc;
00120 #ifdef _GLIBCXX_HAVE_MBSTATE_T
00121   using ::mblen;
00122   using ::mbstowcs;
00123   using ::mbtowc;
00124 #endif // _GLIBCXX_HAVE_MBSTATE_T
00125   using ::qsort;
00126   using ::rand;
00127   using ::realloc;
00128   using ::srand;
00129   using ::strtod;
00130   using ::strtol;
00131   using ::strtoul;
00132   using ::system;
00133 #ifdef _GLIBCXX_USE_WCHAR_T
00134   using ::wcstombs;
00135   using ::wctomb;
00136 #endif // _GLIBCXX_USE_WCHAR_T
00137 
00138 #ifndef __CORRECT_ISO_CPP_STDLIB_H_PROTO
00139   inline long
00140   abs(long __i) { return labs(__i); }
00141 
00142   inline ldiv_t
00143   div(long __i, long __j) { return ldiv(__i, __j); }
00144 #endif
00145 
00146 _GLIBCXX_END_NAMESPACE_VERSION
00147 } // namespace
00148 
00149 #if _GLIBCXX_USE_C99
00150 
00151 #undef _Exit
00152 #undef llabs
00153 #undef lldiv
00154 #undef atoll
00155 #undef strtoll
00156 #undef strtoull
00157 #undef strtof
00158 #undef strtold
00159 
00160 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
00161 {
00162 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00163 
00164 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00165   using ::lldiv_t;
00166 #endif
00167 #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
00168   extern "C" void (_Exit)(int) throw () _GLIBCXX_NORETURN;
00169 #endif
00170 #if !_GLIBCXX_USE_C99_DYNAMIC
00171   using ::_Exit;
00172 #endif
00173 
00174   inline long long
00175   abs(long long __x) { return __x >= 0 ? __x : -__x; }
00176 
00177 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00178   using ::llabs;
00179 
00180   inline lldiv_t
00181   div(long long __n, long long __d)
00182   { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
00183 
00184   using ::lldiv;
00185 #endif
00186 
00187 #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00188   extern "C" long long int (atoll)(const char *) throw ();
00189   extern "C" long long int
00190     (strtoll)(const char * __restrict, char ** __restrict, int) throw ();
00191   extern "C" unsigned long long int
00192     (strtoull)(const char * __restrict, char ** __restrict, int) throw ();
00193 #endif
00194 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00195   using ::atoll;
00196   using ::strtoll;
00197   using ::strtoull;
00198 #endif
00199   using ::strtof;
00200   using ::strtold;
00201 
00202 _GLIBCXX_END_NAMESPACE_VERSION
00203 } // namespace __gnu_cxx
00204 
00205 namespace std
00206 {
00207 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00208   using ::__gnu_cxx::lldiv_t;
00209 #endif
00210   using ::__gnu_cxx::_Exit;
00211   using ::__gnu_cxx::abs;
00212 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00213   using ::__gnu_cxx::llabs;
00214   using ::__gnu_cxx::div;
00215   using ::__gnu_cxx::lldiv;
00216 #endif
00217   using ::__gnu_cxx::atoll;
00218   using ::__gnu_cxx::strtof;
00219   using ::__gnu_cxx::strtoll;
00220   using ::__gnu_cxx::strtoull;
00221   using ::__gnu_cxx::strtold;
00222 } // namespace std
00223 
00224 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00225 
00226 namespace std
00227 {
00228 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00229   // types
00230   using std::lldiv_t;
00231 
00232   // functions
00233   using std::llabs;
00234   using std::lldiv;
00235 #endif
00236 
00237   using std::atoll;
00238   using std::strtoll;
00239   using std::strtoull;
00240 
00241   using std::strtof;
00242   using std::strtold;
00243 
00244   // overloads
00245   using std::abs;
00246 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00247   using std::div;
00248 #endif
00249 } // namespace std
00250 
00251 #endif // __GXX_EXPERIMENTAL_CXX0X__
00252 
00253 #endif // _GLIBCXX_USE_C99
00254 
00255 #endif // !_GLIBCXX_HOSTED
00256 
00257 #endif