cstdlib 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. // -*- C++ -*- forwarding header.
  2. // Copyright (C) 1997-2016 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. // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
  64. #undef abort
  65. #undef abs
  66. #undef atexit
  67. #if __cplusplus >= 201103L
  68. # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
  69. # undef at_quick_exit
  70. # endif
  71. #endif
  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. #if __cplusplus >= 201103L
  89. # ifdef _GLIBCXX_HAVE_QUICK_EXIT
  90. # undef quick_exit
  91. # endif
  92. #endif
  93. #undef rand
  94. #undef realloc
  95. #undef srand
  96. #undef strtod
  97. #undef strtol
  98. #undef strtoul
  99. #undef system
  100. #undef wcstombs
  101. #undef wctomb
  102. extern "C++"
  103. {
  104. namespace std _GLIBCXX_VISIBILITY(default)
  105. {
  106. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  107. using ::div_t;
  108. using ::ldiv_t;
  109. using ::abort;
  110. using ::abs;
  111. using ::atexit;
  112. #if __cplusplus >= 201103L
  113. # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
  114. using ::at_quick_exit;
  115. # endif
  116. #endif
  117. using ::atof;
  118. using ::atoi;
  119. using ::atol;
  120. using ::bsearch;
  121. using ::calloc;
  122. using ::div;
  123. using ::exit;
  124. using ::free;
  125. using ::getenv;
  126. using ::labs;
  127. using ::ldiv;
  128. using ::malloc;
  129. #ifdef _GLIBCXX_HAVE_MBSTATE_T
  130. using ::mblen;
  131. using ::mbstowcs;
  132. using ::mbtowc;
  133. #endif // _GLIBCXX_HAVE_MBSTATE_T
  134. using ::qsort;
  135. #if __cplusplus >= 201103L
  136. # ifdef _GLIBCXX_HAVE_QUICK_EXIT
  137. using ::quick_exit;
  138. # endif
  139. #endif
  140. using ::rand;
  141. using ::realloc;
  142. using ::srand;
  143. using ::strtod;
  144. using ::strtol;
  145. using ::strtoul;
  146. using ::system;
  147. #ifdef _GLIBCXX_USE_WCHAR_T
  148. using ::wcstombs;
  149. using ::wctomb;
  150. #endif // _GLIBCXX_USE_WCHAR_T
  151. #ifndef __CORRECT_ISO_CPP_STDLIB_H_PROTO
  152. inline long
  153. abs(long __i) { return __builtin_labs(__i); }
  154. inline ldiv_t
  155. div(long __i, long __j) { return ldiv(__i, __j); }
  156. #endif
  157. #ifdef _GLIBCXX_USE_LONG_LONG
  158. inline long long
  159. abs(long long __x) { return __builtin_llabs (__x); }
  160. #endif
  161. #if defined(__GLIBCXX_TYPE_INT_N_0)
  162. inline __GLIBCXX_TYPE_INT_N_0
  163. abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
  164. #endif
  165. #if defined(__GLIBCXX_TYPE_INT_N_1)
  166. inline __GLIBCXX_TYPE_INT_N_1
  167. abs(__GLIBCXX_TYPE_INT_N_1 __x) { return __x >= 0 ? __x : -__x; }
  168. #endif
  169. #if defined(__GLIBCXX_TYPE_INT_N_2)
  170. inline __GLIBCXX_TYPE_INT_N_2
  171. abs(__GLIBCXX_TYPE_INT_N_2 __x) { return __x >= 0 ? __x : -__x; }
  172. #endif
  173. #if defined(__GLIBCXX_TYPE_INT_N_3)
  174. inline __GLIBCXX_TYPE_INT_N_3
  175. abs(__GLIBCXX_TYPE_INT_N_3 __x) { return __x >= 0 ? __x : -__x; }
  176. #endif
  177. _GLIBCXX_END_NAMESPACE_VERSION
  178. } // namespace
  179. #if _GLIBCXX_USE_C99_STDLIB
  180. #undef _Exit
  181. #undef llabs
  182. #undef lldiv
  183. #undef atoll
  184. #undef strtoll
  185. #undef strtoull
  186. #undef strtof
  187. #undef strtold
  188. namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
  189. {
  190. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  191. #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  192. using ::lldiv_t;
  193. #endif
  194. #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
  195. extern "C" void (_Exit)(int) throw () _GLIBCXX_NORETURN;
  196. #endif
  197. #if !_GLIBCXX_USE_C99_DYNAMIC
  198. using ::_Exit;
  199. #endif
  200. #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  201. using ::llabs;
  202. inline lldiv_t
  203. div(long long __n, long long __d)
  204. { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
  205. using ::lldiv;
  206. #endif
  207. #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  208. extern "C" long long int (atoll)(const char *) throw ();
  209. extern "C" long long int
  210. (strtoll)(const char * __restrict, char ** __restrict, int) throw ();
  211. extern "C" unsigned long long int
  212. (strtoull)(const char * __restrict, char ** __restrict, int) throw ();
  213. #endif
  214. #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  215. using ::atoll;
  216. using ::strtoll;
  217. using ::strtoull;
  218. #endif
  219. using ::strtof;
  220. using ::strtold;
  221. _GLIBCXX_END_NAMESPACE_VERSION
  222. } // namespace __gnu_cxx
  223. namespace std
  224. {
  225. #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  226. using ::__gnu_cxx::lldiv_t;
  227. #endif
  228. using ::__gnu_cxx::_Exit;
  229. #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  230. using ::__gnu_cxx::llabs;
  231. using ::__gnu_cxx::div;
  232. using ::__gnu_cxx::lldiv;
  233. #endif
  234. using ::__gnu_cxx::atoll;
  235. using ::__gnu_cxx::strtof;
  236. using ::__gnu_cxx::strtoll;
  237. using ::__gnu_cxx::strtoull;
  238. using ::__gnu_cxx::strtold;
  239. } // namespace std
  240. #endif // _GLIBCXX_USE_C99_STDLIB
  241. } // extern "C++"
  242. #endif // !_GLIBCXX_HOSTED
  243. #endif