You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. // -*- C++ -*- forwarding header.
  2. // Copyright (C) 1997-2020 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. namespace std
  44. {
  45. extern "C" void abort(void) throw () _GLIBCXX_NORETURN;
  46. extern "C" int atexit(void (*)(void)) throw ();
  47. extern "C" void exit(int) throw () _GLIBCXX_NORETURN;
  48. #if __cplusplus >= 201103L
  49. # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
  50. extern "C" int at_quick_exit(void (*)(void)) throw ();
  51. # endif
  52. # ifdef _GLIBCXX_HAVE_QUICK_EXIT
  53. extern "C" void quick_exit(int) throw() _GLIBCXX_NORETURN;
  54. # endif
  55. #endif
  56. } // namespace std
  57. #else
  58. // Need to ensure this finds the C library's <stdlib.h> not a libstdc++
  59. // wrapper that might already be installed later in the include search path.
  60. #define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
  61. #include_next <stdlib.h>
  62. #undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS
  63. #include <bits/std_abs.h>
  64. // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
  65. #undef abort
  66. #if __cplusplus >= 201703L && defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)
  67. # undef aligned_alloc
  68. #endif
  69. #undef atexit
  70. #if __cplusplus >= 201103L
  71. # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
  72. # undef at_quick_exit
  73. # endif
  74. #endif
  75. #undef atof
  76. #undef atoi
  77. #undef atol
  78. #undef bsearch
  79. #undef calloc
  80. #undef div
  81. #undef exit
  82. #undef free
  83. #undef getenv
  84. #undef labs
  85. #undef ldiv
  86. #undef malloc
  87. #undef mblen
  88. #undef mbstowcs
  89. #undef mbtowc
  90. #undef qsort
  91. #if __cplusplus >= 201103L
  92. # ifdef _GLIBCXX_HAVE_QUICK_EXIT
  93. # undef quick_exit
  94. # endif
  95. #endif
  96. #undef rand
  97. #undef realloc
  98. #undef srand
  99. #undef strtod
  100. #undef strtol
  101. #undef strtoul
  102. #undef system
  103. #undef wcstombs
  104. #undef wctomb
  105. extern "C++"
  106. {
  107. namespace std _GLIBCXX_VISIBILITY(default)
  108. {
  109. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  110. using ::div_t;
  111. using ::ldiv_t;
  112. using ::abort;
  113. #if __cplusplus >= 201703L && defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)
  114. using ::aligned_alloc;
  115. #endif
  116. using ::atexit;
  117. #if __cplusplus >= 201103L
  118. # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
  119. using ::at_quick_exit;
  120. # endif
  121. #endif
  122. using ::atof;
  123. using ::atoi;
  124. using ::atol;
  125. using ::bsearch;
  126. using ::calloc;
  127. using ::div;
  128. using ::exit;
  129. using ::free;
  130. using ::getenv;
  131. using ::labs;
  132. using ::ldiv;
  133. using ::malloc;
  134. #ifdef _GLIBCXX_HAVE_MBSTATE_T
  135. using ::mblen;
  136. using ::mbstowcs;
  137. using ::mbtowc;
  138. #endif // _GLIBCXX_HAVE_MBSTATE_T
  139. using ::qsort;
  140. #if __cplusplus >= 201103L
  141. # ifdef _GLIBCXX_HAVE_QUICK_EXIT
  142. using ::quick_exit;
  143. # endif
  144. #endif
  145. using ::rand;
  146. using ::realloc;
  147. using ::srand;
  148. using ::strtod;
  149. using ::strtol;
  150. using ::strtoul;
  151. using ::system;
  152. #ifdef _GLIBCXX_USE_WCHAR_T
  153. using ::wcstombs;
  154. using ::wctomb;
  155. #endif // _GLIBCXX_USE_WCHAR_T
  156. #ifndef __CORRECT_ISO_CPP_STDLIB_H_PROTO
  157. inline ldiv_t
  158. div(long __i, long __j) { return ldiv(__i, __j); }
  159. #endif
  160. _GLIBCXX_END_NAMESPACE_VERSION
  161. } // namespace
  162. #if _GLIBCXX_USE_C99_STDLIB
  163. #undef _Exit
  164. #undef llabs
  165. #undef lldiv
  166. #undef atoll
  167. #undef strtoll
  168. #undef strtoull
  169. #undef strtof
  170. #undef strtold
  171. namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
  172. {
  173. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  174. #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  175. using ::lldiv_t;
  176. #endif
  177. #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
  178. extern "C" void (_Exit)(int) throw () _GLIBCXX_NORETURN;
  179. #endif
  180. #if !_GLIBCXX_USE_C99_DYNAMIC
  181. using ::_Exit;
  182. #endif
  183. #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  184. using ::llabs;
  185. inline lldiv_t
  186. div(long long __n, long long __d)
  187. { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
  188. using ::lldiv;
  189. #endif
  190. #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  191. extern "C" long long int (atoll)(const char *) throw ();
  192. extern "C" long long int
  193. (strtoll)(const char * __restrict, char ** __restrict, int) throw ();
  194. extern "C" unsigned long long int
  195. (strtoull)(const char * __restrict, char ** __restrict, int) throw ();
  196. #endif
  197. #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  198. using ::atoll;
  199. using ::strtoll;
  200. using ::strtoull;
  201. #endif
  202. using ::strtof;
  203. using ::strtold;
  204. _GLIBCXX_END_NAMESPACE_VERSION
  205. } // namespace __gnu_cxx
  206. namespace std
  207. {
  208. #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  209. using ::__gnu_cxx::lldiv_t;
  210. #endif
  211. using ::__gnu_cxx::_Exit;
  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. #endif // _GLIBCXX_USE_C99_STDLIB
  224. } // extern "C++"
  225. #endif // !_GLIBCXX_HOSTED
  226. #endif