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