1// -*- C++ -*- forwarding header. 2 3// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 4// 2009, 2010 Free Software Foundation, Inc. 5// 6// This file is part of the GNU ISO C++ Library. This library is free 7// software; you can redistribute it and/or modify it under the 8// terms of the GNU General Public License as published by the 9// Free Software Foundation; either version 3, or (at your option) 10// any later version. 11 12// This library is distributed in the hope that it will be useful, 13// but WITHOUT ANY WARRANTY; without even the implied warranty of 14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15// GNU General Public License for more details. 16 17// Under Section 7 of GPL version 3, you are granted additional 18// permissions described in the GCC Runtime Library Exception, version 19// 3.1, as published by the Free Software Foundation. 20 21// You should have received a copy of the GNU General Public License and 22// a copy of the GCC Runtime Library Exception along with this program; 23// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 24// <http://www.gnu.org/licenses/>. 25 26/** @file include/cstdlib 27 * This is a Standard C++ Library file. You should @c #include this file 28 * in your programs, rather than any of the @a *.h implementation files. 29 * 30 * This is the C++ version of the Standard C Library header @c stdlib.h, 31 * and its contents are (mostly) the same as that header, but are all 32 * contained in the namespace @c std (except for names which are defined 33 * as macros in C). 34 */ 35 36// 37// ISO C++ 14882: 20.4.6 C library 38// 39 40#ifndef _GLIBCXX_CSTDLIB 41#define _GLIBCXX_CSTDLIB 1 42 43#pragma GCC system_header 44 45#include <bits/c++config.h> 46 47#if !_GLIBCXX_HOSTED 48// The C standard does not require a freestanding implementation to 49// provide <stdlib.h>. However, the C++ standard does still require 50// <cstdlib> -- but only the functionality mentioned in 51// [lib.support.start.term]. 52 53#define EXIT_SUCCESS 0 54#define EXIT_FAILURE 1 55 56namespace std 57{ 58 extern "C" void abort(void) throw () _GLIBCXX_NORETURN; 59 extern "C" int atexit(void (*)()) throw (); 60 extern "C" void exit(int) throw () _GLIBCXX_NORETURN; 61} // namespace 62 63#else 64 65#include <stdlib.h> 66 67// Get rid of those macros defined in <stdlib.h> in lieu of real functions. 68#undef abort 69#undef abs 70#undef atexit 71#undef atof 72#undef atoi 73#undef atol 74#undef bsearch 75#undef calloc 76#undef div 77#undef exit 78#undef free 79#undef getenv 80#undef labs 81#undef ldiv 82#undef malloc 83#undef mblen 84#undef mbstowcs 85#undef mbtowc 86#undef qsort 87#undef rand 88#undef realloc 89#undef srand 90#undef strtod 91#undef strtol 92#undef strtoul 93#undef system 94#undef wcstombs 95#undef wctomb 96 97namespace std _GLIBCXX_VISIBILITY(default) 98{ 99_GLIBCXX_BEGIN_NAMESPACE_VERSION 100 101 using ::div_t; 102 using ::ldiv_t; 103 104 using ::abort; 105 using ::abs; 106 using ::atexit; 107 using ::atof; 108 using ::atoi; 109 using ::atol; 110 using ::bsearch; 111 using ::calloc; 112 using ::div; 113 using ::exit; 114 using ::free; 115 using ::getenv; 116 using ::labs; 117 using ::ldiv; 118 using ::malloc; 119#ifdef _GLIBCXX_HAVE_MBSTATE_T 120 using ::mblen; 121 using ::mbstowcs; 122 using ::mbtowc; 123#endif // _GLIBCXX_HAVE_MBSTATE_T 124 using ::qsort; 125 using ::rand; 126 using ::realloc; 127 using ::srand; 128 using ::strtod; 129 using ::strtol; 130 using ::strtoul; 131 using ::system; 132#ifdef _GLIBCXX_USE_WCHAR_T 133 using ::wcstombs; 134 using ::wctomb; 135#endif // _GLIBCXX_USE_WCHAR_T 136 137 inline long 138 abs(long __i) { return labs(__i); } 139 140 inline ldiv_t 141 div(long __i, long __j) { return ldiv(__i, __j); } 142 143_GLIBCXX_END_NAMESPACE_VERSION 144} // namespace 145 146#if _GLIBCXX_USE_C99 147 148#undef _Exit 149#undef llabs 150#undef lldiv 151#undef atoll 152#undef strtoll 153#undef strtoull 154#undef strtof 155#undef strtold 156 157namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) 158{ 159_GLIBCXX_BEGIN_NAMESPACE_VERSION 160 161#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC 162 using ::lldiv_t; 163#endif 164#if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC 165 extern "C" void (_Exit)(int) throw () _GLIBCXX_NORETURN; 166#endif 167#if !_GLIBCXX_USE_C99_DYNAMIC 168 using ::_Exit; 169#endif 170 171 inline long long 172 abs(long long __x) { return __x >= 0 ? __x : -__x; } 173 174#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC 175 using ::llabs; 176 177 inline lldiv_t 178 div(long long __n, long long __d) 179 { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; } 180 181 using ::lldiv; 182#endif 183 184#if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC 185 extern "C" long long int (atoll)(const char *) throw (); 186 extern "C" long long int 187 (strtoll)(const char * __restrict, char ** __restrict, int) throw (); 188 extern "C" unsigned long long int 189 (strtoull)(const char * __restrict, char ** __restrict, int) throw (); 190#endif 191#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC 192 using ::atoll; 193 using ::strtoll; 194 using ::strtoull; 195#endif 196 using ::strtof; 197 using ::strtold; 198 199_GLIBCXX_END_NAMESPACE_VERSION 200} // namespace __gnu_cxx 201 202namespace std 203{ 204#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC 205 using ::__gnu_cxx::lldiv_t; 206#endif 207 using ::__gnu_cxx::_Exit; 208 using ::__gnu_cxx::abs; 209#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC 210 using ::__gnu_cxx::llabs; 211 using ::__gnu_cxx::div; 212 using ::__gnu_cxx::lldiv; 213#endif 214 using ::__gnu_cxx::atoll; 215 using ::__gnu_cxx::strtof; 216 using ::__gnu_cxx::strtoll; 217 using ::__gnu_cxx::strtoull; 218 using ::__gnu_cxx::strtold; 219} // namespace std 220 221#endif // _GLIBCXX_USE_C99 222 223#endif // !_GLIBCXX_HOSTED 224 225#endif 226