cstdlib 6.4 KB

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