libstdc++
cstdlib
Go to the documentation of this file.
00001 // -*- C++ -*- forwarding header.
00002 
00003 // Copyright (C) 1997-2016 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 // Need to ensure this finds the C library's <stdlib.h> not a libstdc++
00073 // wrapper that might already be installed later in the include search path.
00074 #define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
00075 #include_next <stdlib.h>
00076 #undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS
00077 
00078 // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
00079 #undef abort
00080 #undef abs
00081 #undef atexit
00082 #if __cplusplus >= 201103L
00083 # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
00084 #  undef at_quick_exit
00085 # endif
00086 #endif
00087 #undef atof
00088 #undef atoi
00089 #undef atol
00090 #undef bsearch
00091 #undef calloc
00092 #undef div
00093 #undef exit
00094 #undef free
00095 #undef getenv
00096 #undef labs
00097 #undef ldiv
00098 #undef malloc
00099 #undef mblen
00100 #undef mbstowcs
00101 #undef mbtowc
00102 #undef qsort
00103 #if __cplusplus >= 201103L
00104 # ifdef _GLIBCXX_HAVE_QUICK_EXIT
00105 #  undef quick_exit
00106 # endif
00107 #endif
00108 #undef rand
00109 #undef realloc
00110 #undef srand
00111 #undef strtod
00112 #undef strtol
00113 #undef strtoul
00114 #undef system
00115 #undef wcstombs
00116 #undef wctomb
00117 
00118 extern "C++"
00119 {
00120 namespace std _GLIBCXX_VISIBILITY(default)
00121 {
00122 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00123 
00124   using ::div_t;
00125   using ::ldiv_t;
00126 
00127   using ::abort;
00128   using ::abs;
00129   using ::atexit;
00130 #if __cplusplus >= 201103L
00131 # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
00132   using ::at_quick_exit;
00133 # endif
00134 #endif
00135   using ::atof;
00136   using ::atoi;
00137   using ::atol;
00138   using ::bsearch;
00139   using ::calloc;
00140   using ::div;
00141   using ::exit;
00142   using ::free;
00143   using ::getenv;
00144   using ::labs;
00145   using ::ldiv;
00146   using ::malloc;
00147 #ifdef _GLIBCXX_HAVE_MBSTATE_T
00148   using ::mblen;
00149   using ::mbstowcs;
00150   using ::mbtowc;
00151 #endif // _GLIBCXX_HAVE_MBSTATE_T
00152   using ::qsort;
00153 #if __cplusplus >= 201103L
00154 # ifdef _GLIBCXX_HAVE_QUICK_EXIT
00155   using ::quick_exit;
00156 # endif
00157 #endif
00158   using ::rand;
00159   using ::realloc;
00160   using ::srand;
00161   using ::strtod;
00162   using ::strtol;
00163   using ::strtoul;
00164   using ::system;
00165 #ifdef _GLIBCXX_USE_WCHAR_T
00166   using ::wcstombs;
00167   using ::wctomb;
00168 #endif // _GLIBCXX_USE_WCHAR_T
00169 
00170 #ifndef __CORRECT_ISO_CPP_STDLIB_H_PROTO
00171   inline long
00172   abs(long __i) { return __builtin_labs(__i); }
00173 
00174   inline ldiv_t
00175   div(long __i, long __j) { return ldiv(__i, __j); }
00176 #endif
00177 
00178 #ifdef _GLIBCXX_USE_LONG_LONG
00179   inline long long
00180   abs(long long __x) { return __builtin_llabs (__x); }
00181 #endif
00182 
00183 #if defined(__GLIBCXX_TYPE_INT_N_0)
00184   inline __GLIBCXX_TYPE_INT_N_0
00185   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
00186 #endif
00187 #if defined(__GLIBCXX_TYPE_INT_N_1)
00188   inline __GLIBCXX_TYPE_INT_N_1
00189   abs(__GLIBCXX_TYPE_INT_N_1 __x) { return __x >= 0 ? __x : -__x; }
00190 #endif
00191 #if defined(__GLIBCXX_TYPE_INT_N_2)
00192   inline __GLIBCXX_TYPE_INT_N_2
00193   abs(__GLIBCXX_TYPE_INT_N_2 __x) { return __x >= 0 ? __x : -__x; }
00194 #endif
00195 #if defined(__GLIBCXX_TYPE_INT_N_3)
00196   inline __GLIBCXX_TYPE_INT_N_3
00197   abs(__GLIBCXX_TYPE_INT_N_3 __x) { return __x >= 0 ? __x : -__x; }
00198 #endif
00199 
00200 
00201 _GLIBCXX_END_NAMESPACE_VERSION
00202 } // namespace
00203 
00204 #if _GLIBCXX_USE_C99_STDLIB
00205 
00206 #undef _Exit
00207 #undef llabs
00208 #undef lldiv
00209 #undef atoll
00210 #undef strtoll
00211 #undef strtoull
00212 #undef strtof
00213 #undef strtold
00214 
00215 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
00216 {
00217 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00218 
00219 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00220   using ::lldiv_t;
00221 #endif
00222 #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
00223   extern "C" void (_Exit)(int) throw () _GLIBCXX_NORETURN;
00224 #endif
00225 #if !_GLIBCXX_USE_C99_DYNAMIC
00226   using ::_Exit;
00227 #endif
00228 
00229 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00230   using ::llabs;
00231 
00232   inline lldiv_t
00233   div(long long __n, long long __d)
00234   { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
00235 
00236   using ::lldiv;
00237 #endif
00238 
00239 #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00240   extern "C" long long int (atoll)(const char *) throw ();
00241   extern "C" long long int
00242     (strtoll)(const char * __restrict, char ** __restrict, int) throw ();
00243   extern "C" unsigned long long int
00244     (strtoull)(const char * __restrict, char ** __restrict, int) throw ();
00245 #endif
00246 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00247   using ::atoll;
00248   using ::strtoll;
00249   using ::strtoull;
00250 #endif
00251   using ::strtof;
00252   using ::strtold;
00253 
00254 _GLIBCXX_END_NAMESPACE_VERSION
00255 } // namespace __gnu_cxx
00256 
00257 namespace std
00258 {
00259 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00260   using ::__gnu_cxx::lldiv_t;
00261 #endif
00262   using ::__gnu_cxx::_Exit;
00263 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
00264   using ::__gnu_cxx::llabs;
00265   using ::__gnu_cxx::div;
00266   using ::__gnu_cxx::lldiv;
00267 #endif
00268   using ::__gnu_cxx::atoll;
00269   using ::__gnu_cxx::strtof;
00270   using ::__gnu_cxx::strtoll;
00271   using ::__gnu_cxx::strtoull;
00272   using ::__gnu_cxx::strtold;
00273 } // namespace std
00274 
00275 #endif // _GLIBCXX_USE_C99_STDLIB
00276 
00277 } // extern "C++"
00278 
00279 #endif // !_GLIBCXX_HOSTED
00280 
00281 #endif