cstdlib 6.4 KB

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