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
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   inline long
00139   abs(long __i) { return labs(__i); }
00140 
00141   inline ldiv_t
00142   div(long __i, long __j) { return ldiv(__i, __j); }
00143 
00144 _GLIBCXX_END_NAMESPACE_VERSION
00145 } // namespace
00146 
00147 #if _GLIBCXX_USE_C99
00148 
00149 #undef _Exit
00150 #undef llabs
00151 #undef lldiv
00152 #undef atoll
00153 #undef strtoll
00154 #undef strtoull
00155 #undef strtof
00156 #undef strtold
00157 
00158 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
00159 {
00160 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00161 
00162 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00163   using ::lldiv_t;
00164 #endif
00165 #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
00166   extern "C" void (_Exit)(int) throw () _GLIBCXX_NORETURN;
00167 #endif
00168 #if !_GLIBCXX_USE_C99_DYNAMIC
00169   using ::_Exit;
00170 #endif
00171 
00172   inline long long
00173   abs(long long __x) { return __x >= 0 ? __x : -__x; }
00174 
00175 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00176   using ::llabs;
00177 
00178   inline lldiv_t
00179   div(long long __n, long long __d)
00180   { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
00181 
00182   using ::lldiv;
00183 #endif
00184 
00185 #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00186   extern "C" long long int (atoll)(const char *) throw ();
00187   extern "C" long long int
00188     (strtoll)(const char * __restrict, char ** __restrict, int) throw ();
00189   extern "C" unsigned long long int
00190     (strtoull)(const char * __restrict, char ** __restrict, int) throw ();
00191 #endif
00192 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00193   using ::atoll;
00194   using ::strtoll;
00195   using ::strtoull;
00196 #endif
00197   using ::strtof;
00198   using ::strtold;
00199 
00200 _GLIBCXX_END_NAMESPACE_VERSION
00201 } // namespace __gnu_cxx
00202 
00203 namespace std
00204 {
00205 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00206   using ::__gnu_cxx::lldiv_t;
00207 #endif
00208   using ::__gnu_cxx::_Exit;
00209   using ::__gnu_cxx::abs;
00210 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00211   using ::__gnu_cxx::llabs;
00212   using ::__gnu_cxx::div;
00213   using ::__gnu_cxx::lldiv;
00214 #endif
00215   using ::__gnu_cxx::atoll;
00216   using ::__gnu_cxx::strtof;
00217   using ::__gnu_cxx::strtoll;
00218   using ::__gnu_cxx::strtoull;
00219   using ::__gnu_cxx::strtold;
00220 } // namespace std
00221 
00222 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00223 
00224 namespace std
00225 {
00226 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00227   // types
00228   using std::lldiv_t;
00229 
00230   // functions
00231   using std::llabs;
00232   using std::lldiv;
00233 #endif
00234 
00235   using std::atoll;
00236   using std::strtoll;
00237   using std::strtoull;
00238 
00239   using std::strtof;
00240   using std::strtold;
00241 
00242   // overloads
00243   using std::abs;
00244 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00245   using std::div;
00246 #endif
00247 } // namespace std
00248 
00249 #endif // __GXX_EXPERIMENTAL_CXX0X__
00250 
00251 #endif // _GLIBCXX_USE_C99
00252 
00253 #endif // !_GLIBCXX_HOSTED
00254 
00255 #endif