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