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