libstdc++
cstdlib
Go to the documentation of this file.
00001 // -*- C++ -*- forwarding header.
00002 
00003 // Copyright (C) 1997-2015 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 (*)(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 (*)(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(__GLIBCXX_TYPE_INT_N_0)
00178   inline __GLIBCXX_TYPE_INT_N_0
00179   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
00180 #endif
00181 #if defined(__GLIBCXX_TYPE_INT_N_1)
00182   inline __GLIBCXX_TYPE_INT_N_1
00183   abs(__GLIBCXX_TYPE_INT_N_1 __x) { return __x >= 0 ? __x : -__x; }
00184 #endif
00185 #if defined(__GLIBCXX_TYPE_INT_N_2)
00186   inline __GLIBCXX_TYPE_INT_N_2
00187   abs(__GLIBCXX_TYPE_INT_N_2 __x) { return __x >= 0 ? __x : -__x; }
00188 #endif
00189 #if defined(__GLIBCXX_TYPE_INT_N_3)
00190   inline __GLIBCXX_TYPE_INT_N_3
00191   abs(__GLIBCXX_TYPE_INT_N_3 __x) { return __x >= 0 ? __x : -__x; }
00192 #endif
00193 
00194 
00195 _GLIBCXX_END_NAMESPACE_VERSION
00196 } // namespace
00197 
00198 #if _GLIBCXX_USE_C99
00199 
00200 #undef _Exit
00201 #undef llabs
00202 #undef lldiv
00203 #undef atoll
00204 #undef strtoll
00205 #undef strtoull
00206 #undef strtof
00207 #undef strtold
00208 
00209 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
00210 {
00211 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00212 
00213 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00214   using ::lldiv_t;
00215 #endif
00216 #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
00217   extern "C" void (_Exit)(int) throw () _GLIBCXX_NORETURN;
00218 #endif
00219 #if !_GLIBCXX_USE_C99_DYNAMIC
00220   using ::_Exit;
00221 #endif
00222 
00223 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00224   using ::llabs;
00225 
00226   inline lldiv_t
00227   div(long long __n, long long __d)
00228   { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
00229 
00230   using ::lldiv;
00231 #endif
00232 
00233 #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00234   extern "C" long long int (atoll)(const char *) throw ();
00235   extern "C" long long int
00236     (strtoll)(const char * __restrict, char ** __restrict, int) throw ();
00237   extern "C" unsigned long long int
00238     (strtoull)(const char * __restrict, char ** __restrict, int) throw ();
00239 #endif
00240 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00241   using ::atoll;
00242   using ::strtoll;
00243   using ::strtoull;
00244 #endif
00245   using ::strtof;
00246   using ::strtold;
00247 
00248 _GLIBCXX_END_NAMESPACE_VERSION
00249 } // namespace __gnu_cxx
00250 
00251 namespace std
00252 {
00253 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00254   using ::__gnu_cxx::lldiv_t;
00255 #endif
00256   using ::__gnu_cxx::_Exit;
00257 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00258   using ::__gnu_cxx::llabs;
00259   using ::__gnu_cxx::div;
00260   using ::__gnu_cxx::lldiv;
00261 #endif
00262   using ::__gnu_cxx::atoll;
00263   using ::__gnu_cxx::strtof;
00264   using ::__gnu_cxx::strtoll;
00265   using ::__gnu_cxx::strtoull;
00266   using ::__gnu_cxx::strtold;
00267 } // namespace std
00268 
00269 #endif // _GLIBCXX_USE_C99
00270 
00271 #endif // !_GLIBCXX_HOSTED
00272 
00273 #endif