cstdlib 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. // -*- C++ -*- forwarding header.
  2. // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
  3. // 2006, 2007, 2008, 2009
  4. // Free Software Foundation, Inc.
  5. //
  6. // This file is part of the GNU ISO C++ Library. This library is free
  7. // software; you can redistribute it and/or modify it under the
  8. // terms of the GNU General Public License as published by the
  9. // Free Software Foundation; either version 3, or (at your option)
  10. // any later version.
  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. // Under Section 7 of GPL version 3, you are granted additional
  16. // permissions described in the GCC Runtime Library Exception, version
  17. // 3.1, as published by the Free Software Foundation.
  18. // You should have received a copy of the GNU General Public License and
  19. // a copy of the GCC Runtime Library Exception along with this program;
  20. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  21. // <http://www.gnu.org/licenses/>.
  22. /** @file include/cstdlib
  23. * This is a Standard C++ Library file. You should @c #include this file
  24. * in your programs, rather than any of the "*.h" implementation files.
  25. *
  26. * This is the C++ version of the Standard C Library header @c stdlib.h,
  27. * and its contents are (mostly) the same as that header, but are all
  28. * contained in the namespace @c std (except for names which are defined
  29. * as macros in C).
  30. */
  31. //
  32. // ISO C++ 14882: 20.4.6 C library
  33. //
  34. #pragma GCC system_header
  35. #include <bits/c++config.h>
  36. #include <cstddef>
  37. #ifndef _GLIBCXX_CSTDLIB
  38. #define _GLIBCXX_CSTDLIB 1
  39. #if !_GLIBCXX_HOSTED
  40. // The C standard does not require a freestanding implementation to
  41. // provide <stdlib.h>. However, the C++ standard does still require
  42. // <cstdlib> -- but only the functionality mentioned in
  43. // [lib.support.start.term].
  44. #define EXIT_SUCCESS 0
  45. #define EXIT_FAILURE 1
  46. _GLIBCXX_BEGIN_NAMESPACE(std)
  47. extern "C" void abort(void);
  48. extern "C" int atexit(void (*)());
  49. extern "C" void exit(int);
  50. _GLIBCXX_END_NAMESPACE
  51. #else
  52. #include <stdlib.h>
  53. // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
  54. #undef abort
  55. #undef abs
  56. #undef atexit
  57. #undef atof
  58. #undef atoi
  59. #undef atol
  60. #undef bsearch
  61. #undef calloc
  62. #undef div
  63. #undef exit
  64. #undef free
  65. #undef getenv
  66. #undef labs
  67. #undef ldiv
  68. #undef malloc
  69. #undef mblen
  70. #undef mbstowcs
  71. #undef mbtowc
  72. #undef qsort
  73. #undef rand
  74. #undef realloc
  75. #undef srand
  76. #undef strtod
  77. #undef strtol
  78. #undef strtoul
  79. #undef system
  80. #undef wcstombs
  81. #undef wctomb
  82. _GLIBCXX_BEGIN_NAMESPACE(std)
  83. using ::div_t;
  84. using ::ldiv_t;
  85. using ::abort;
  86. using ::abs;
  87. using ::atexit;
  88. using ::atof;
  89. using ::atoi;
  90. using ::atol;
  91. using ::bsearch;
  92. using ::calloc;
  93. using ::div;
  94. using ::exit;
  95. using ::free;
  96. using ::getenv;
  97. using ::labs;
  98. using ::ldiv;
  99. using ::malloc;
  100. #ifdef _GLIBCXX_HAVE_MBSTATE_T
  101. using ::mblen;
  102. using ::mbstowcs;
  103. using ::mbtowc;
  104. #endif // _GLIBCXX_HAVE_MBSTATE_T
  105. using ::qsort;
  106. using ::rand;
  107. using ::realloc;
  108. using ::srand;
  109. using ::strtod;
  110. using ::strtol;
  111. using ::strtoul;
  112. using ::system;
  113. #ifdef _GLIBCXX_USE_WCHAR_T
  114. using ::wcstombs;
  115. using ::wctomb;
  116. #endif // _GLIBCXX_USE_WCHAR_T
  117. inline long
  118. abs(long __i) { return labs(__i); }
  119. inline ldiv_t
  120. div(long __i, long __j) { return ldiv(__i, __j); }
  121. _GLIBCXX_END_NAMESPACE
  122. #if _GLIBCXX_USE_C99
  123. #undef _Exit
  124. #undef llabs
  125. #undef lldiv
  126. #undef atoll
  127. #undef strtoll
  128. #undef strtoull
  129. #undef strtof
  130. #undef strtold
  131. _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
  132. #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  133. using ::lldiv_t;
  134. #endif
  135. #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
  136. extern "C" void (_Exit)(int);
  137. #endif
  138. #if !_GLIBCXX_USE_C99_DYNAMIC
  139. using ::_Exit;
  140. #endif
  141. inline long long
  142. abs(long long __x) { return __x >= 0 ? __x : -__x; }
  143. #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  144. using ::llabs;
  145. inline lldiv_t
  146. div(long long __n, long long __d)
  147. { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
  148. using ::lldiv;
  149. #endif
  150. #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  151. extern "C" long long int (atoll)(const char *);
  152. extern "C" long long int
  153. (strtoll)(const char * restrict, char ** restrict, int);
  154. extern "C" unsigned long long int
  155. (strtoull)(const char * restrict, char ** restrict, int);
  156. #endif
  157. #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  158. using ::atoll;
  159. using ::strtoll;
  160. using ::strtoull;
  161. #endif
  162. using ::strtof;
  163. using ::strtold;
  164. _GLIBCXX_END_NAMESPACE
  165. _GLIBCXX_BEGIN_NAMESPACE(std)
  166. #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  167. using ::__gnu_cxx::lldiv_t;
  168. #endif
  169. using ::__gnu_cxx::_Exit;
  170. using ::__gnu_cxx::abs;
  171. #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
  172. using ::__gnu_cxx::llabs;
  173. using ::__gnu_cxx::div;
  174. using ::__gnu_cxx::lldiv;
  175. #endif
  176. using ::__gnu_cxx::atoll;
  177. using ::__gnu_cxx::strtof;
  178. using ::__gnu_cxx::strtoll;
  179. using ::__gnu_cxx::strtoull;
  180. using ::__gnu_cxx::strtold;
  181. _GLIBCXX_END_NAMESPACE
  182. #endif // _GLIBCXX_USE_C99
  183. #ifdef __GXX_EXPERIMENTAL_CXX0X__
  184. # if defined(_GLIBCXX_INCLUDE_AS_TR1)
  185. # error C++0x header cannot be included from TR1 header
  186. # endif
  187. # if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
  188. # include <tr1_impl/cstdlib>
  189. # else
  190. # define _GLIBCXX_INCLUDE_AS_CXX0X
  191. # define _GLIBCXX_BEGIN_NAMESPACE_TR1
  192. # define _GLIBCXX_END_NAMESPACE_TR1
  193. # define _GLIBCXX_TR1
  194. # include <tr1_impl/cstdlib>
  195. # undef _GLIBCXX_TR1
  196. # undef _GLIBCXX_END_NAMESPACE_TR1
  197. # undef _GLIBCXX_BEGIN_NAMESPACE_TR1
  198. # undef _GLIBCXX_INCLUDE_AS_CXX0X
  199. # endif
  200. #endif
  201. #endif // !_GLIBCXX_HOSTED
  202. #endif