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 _GLIBCXX_BEGIN_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 
00063 _GLIBCXX_END_NAMESPACE
00064 
00065 #else
00066 
00067 #include <stdlib.h>
00068 
00069 // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
00070 #undef abort
00071 #undef abs
00072 #undef atexit
00073 #undef atof
00074 #undef atoi
00075 #undef atol
00076 #undef bsearch
00077 #undef calloc
00078 #undef div
00079 #undef exit
00080 #undef free
00081 #undef getenv
00082 #undef labs
00083 #undef ldiv
00084 #undef malloc
00085 #undef mblen
00086 #undef mbstowcs
00087 #undef mbtowc
00088 #undef qsort
00089 #undef rand
00090 #undef realloc
00091 #undef srand
00092 #undef strtod
00093 #undef strtol
00094 #undef strtoul
00095 #undef system
00096 #undef wcstombs
00097 #undef wctomb
00098 
00099 _GLIBCXX_BEGIN_NAMESPACE(std)
00100 
00101   using ::div_t;
00102   using ::ldiv_t;
00103 
00104   using ::abort;
00105   using ::abs;
00106   using ::atexit;
00107   using ::atof;
00108   using ::atoi;
00109   using ::atol;
00110   using ::bsearch;
00111   using ::calloc;
00112   using ::div;
00113   using ::exit;
00114   using ::free;
00115   using ::getenv;
00116   using ::labs;
00117   using ::ldiv;
00118   using ::malloc;
00119 #ifdef _GLIBCXX_HAVE_MBSTATE_T
00120   using ::mblen;
00121   using ::mbstowcs;
00122   using ::mbtowc;
00123 #endif // _GLIBCXX_HAVE_MBSTATE_T
00124   using ::qsort;
00125   using ::rand;
00126   using ::realloc;
00127   using ::srand;
00128   using ::strtod;
00129   using ::strtol;
00130   using ::strtoul;
00131   using ::system;
00132 #ifdef _GLIBCXX_USE_WCHAR_T
00133   using ::wcstombs;
00134   using ::wctomb;
00135 #endif // _GLIBCXX_USE_WCHAR_T
00136 
00137   inline long
00138   abs(long __i) { return labs(__i); }
00139 
00140   inline ldiv_t
00141   div(long __i, long __j) { return ldiv(__i, __j); }
00142 
00143 _GLIBCXX_END_NAMESPACE
00144 
00145 #if _GLIBCXX_USE_C99
00146 
00147 #undef _Exit
00148 #undef llabs
00149 #undef lldiv
00150 #undef atoll
00151 #undef strtoll
00152 #undef strtoull
00153 #undef strtof
00154 #undef strtold
00155 
00156 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
00157 
00158 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00159   using ::lldiv_t;
00160 #endif
00161 #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
00162   extern "C" void (_Exit)(int) throw () _GLIBCXX_NORETURN;
00163 #endif
00164 #if !_GLIBCXX_USE_C99_DYNAMIC
00165   using ::_Exit;
00166 #endif
00167 
00168   inline long long
00169   abs(long long __x) { return __x >= 0 ? __x : -__x; }
00170 
00171 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00172   using ::llabs;
00173 
00174   inline lldiv_t
00175   div(long long __n, long long __d)
00176   { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
00177 
00178   using ::lldiv;
00179 #endif
00180 
00181 #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00182   extern "C" long long int (atoll)(const char *) throw ();
00183   extern "C" long long int
00184     (strtoll)(const char * __restrict, char ** __restrict, int) throw ();
00185   extern "C" unsigned long long int
00186     (strtoull)(const char * __restrict, char ** __restrict, int) throw ();
00187 #endif
00188 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00189   using ::atoll;
00190   using ::strtoll;
00191   using ::strtoull;
00192 #endif
00193   using ::strtof;
00194   using ::strtold;
00195 
00196 _GLIBCXX_END_NAMESPACE
00197 
00198 _GLIBCXX_BEGIN_NAMESPACE(std)
00199 
00200 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00201   using ::__gnu_cxx::lldiv_t;
00202 #endif
00203   using ::__gnu_cxx::_Exit;
00204   using ::__gnu_cxx::abs;
00205 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00206   using ::__gnu_cxx::llabs;
00207   using ::__gnu_cxx::div;
00208   using ::__gnu_cxx::lldiv;
00209 #endif
00210   using ::__gnu_cxx::atoll;
00211   using ::__gnu_cxx::strtof;
00212   using ::__gnu_cxx::strtoll;
00213   using ::__gnu_cxx::strtoull;
00214   using ::__gnu_cxx::strtold;
00215 
00216 _GLIBCXX_END_NAMESPACE
00217 
00218 #endif // _GLIBCXX_USE_C99
00219 
00220 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00221 #  if defined(_GLIBCXX_INCLUDE_AS_TR1)
00222 #    error C++0x header cannot be included from TR1 header
00223 #  endif
00224 #  if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
00225 #    include <tr1_impl/cstdlib>
00226 #  else
00227 #    define _GLIBCXX_INCLUDE_AS_CXX0X
00228 #    define _GLIBCXX_BEGIN_NAMESPACE_TR1
00229 #    define _GLIBCXX_END_NAMESPACE_TR1
00230 #    define _GLIBCXX_TR1
00231 #    include <tr1_impl/cstdlib>
00232 #    undef _GLIBCXX_TR1
00233 #    undef _GLIBCXX_END_NAMESPACE_TR1
00234 #    undef _GLIBCXX_BEGIN_NAMESPACE_TR1
00235 #    undef _GLIBCXX_INCLUDE_AS_CXX0X
00236 #  endif
00237 #endif
00238 
00239 #endif // !_GLIBCXX_HOSTED
00240 
00241 #endif