_cstdlib.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (c) 1999
  3. * Boris Fomitchev
  4. *
  5. * This material is provided "as is", with absolutely no warranty expressed
  6. * or implied. Any use is at your own risk.
  7. *
  8. * Permission to use or copy this software for any purpose is hereby granted
  9. * without fee, provided the above notices are retained on all copies.
  10. * Permission to modify the code and to distribute modified code is granted,
  11. * provided the above notices are retained, and a notice that the code was
  12. * modified is included with the above copyright notice.
  13. *
  14. */
  15. #ifndef _STLP_INTERNAL_CSTDLIB
  16. #define _STLP_INTERNAL_CSTDLIB
  17. #if defined (_STLP_USE_NEW_C_HEADERS)
  18. # if defined (_STLP_HAS_INCLUDE_NEXT)
  19. # include_next <cstdlib>
  20. # else
  21. # include _STLP_NATIVE_CPP_C_HEADER(cstdlib)
  22. # endif
  23. #else
  24. # include <stdlib.h>
  25. #endif
  26. #if defined (__BORLANDC__) && !defined (__linux__)
  27. /* Borland process.h header do not bring anything here and is just included
  28. * in order to avoid inclusion later. This header cannot be included later
  29. * because Borland compiler consider that for instance the abort function
  30. * defined as extern "C" cannot be overloaded and it finds 2 "overloads",
  31. * once in native std namespace and the other in STLport namespace...
  32. */
  33. # include <process.h>
  34. #endif
  35. /* on evc3/evc4 including stdlib.h also defines setjmp macro */
  36. #if defined (_STLP_WCE)
  37. # define _STLP_NATIVE_SETJMP_H_INCLUDED
  38. #endif
  39. #if defined (__MSL__) && (__MSL__ <= 0x5003)
  40. namespace std {
  41. typedef ::div_t div_t;
  42. typedef ::ldiv_t ldiv_t;
  43. # ifdef __MSL_LONGLONG_SUPPORT__
  44. typedef ::lldiv_t lldiv_t;
  45. # endif
  46. }
  47. #endif
  48. #ifdef _STLP_IMPORT_VENDOR_CSTD
  49. _STLP_BEGIN_NAMESPACE
  50. using _STLP_VENDOR_CSTD::div_t;
  51. using _STLP_VENDOR_CSTD::ldiv_t;
  52. using _STLP_VENDOR_CSTD::size_t;
  53. # ifndef _STLP_NO_CSTD_FUNCTION_IMPORTS
  54. # ifndef _STLP_WCE
  55. // these functions just don't exist on Windows CE
  56. using _STLP_VENDOR_CSTD::abort;
  57. #if !defined (_STLP_SGX_CONFIG)
  58. using _STLP_VENDOR_CSTD::getenv;
  59. using _STLP_VENDOR_CSTD::mblen;
  60. using _STLP_VENDOR_CSTD::mbtowc;
  61. using _STLP_VENDOR_CSTD::system;
  62. # endif /* !_STLP_SGX_CONFIG */
  63. using _STLP_VENDOR_CSTD::bsearch;
  64. # endif
  65. #if !defined (_STLP_SGX_CONFIG)
  66. using _STLP_VENDOR_CSTD::atexit;
  67. using _STLP_VENDOR_CSTD::exit;
  68. # endif /* !_STLP_SGX_CONFIG */
  69. using _STLP_VENDOR_CSTD::calloc;
  70. using _STLP_VENDOR_CSTD::free;
  71. using _STLP_VENDOR_CSTD::malloc;
  72. using _STLP_VENDOR_CSTD::realloc;
  73. using _STLP_VENDOR_CSTD::atof;
  74. using _STLP_VENDOR_CSTD::atoi;
  75. using _STLP_VENDOR_CSTD::atol;
  76. #if !defined (_STLP_SGX_CONFIG)
  77. using _STLP_VENDOR_CSTD::mbstowcs;
  78. # endif /* !_STLP_SGX_CONFIG */
  79. using _STLP_VENDOR_CSTD::strtod;
  80. using _STLP_VENDOR_CSTD::strtol;
  81. using _STLP_VENDOR_CSTD::strtoul;
  82. # if !(defined (_STLP_NO_NATIVE_WIDE_STREAMS) || defined (_STLP_NO_NATIVE_MBSTATE_T))
  83. using _STLP_VENDOR_CSTD::wcstombs;
  84. # ifndef _STLP_WCE
  85. using _STLP_VENDOR_CSTD::wctomb;
  86. # endif
  87. # endif
  88. using _STLP_VENDOR_CSTD::qsort;
  89. using _STLP_VENDOR_CSTD::labs;
  90. using _STLP_VENDOR_CSTD::ldiv;
  91. # if defined (_STLP_LONG_LONG) && !defined (_STLP_NO_VENDOR_STDLIB_L)
  92. # if !defined(__sun)
  93. using _STLP_VENDOR_CSTD::llabs;
  94. using _STLP_VENDOR_CSTD::lldiv_t;
  95. using _STLP_VENDOR_CSTD::lldiv;
  96. # else
  97. using ::llabs;
  98. using ::lldiv_t;
  99. using ::lldiv;
  100. # endif
  101. # endif
  102. #if !defined (_STLP_SGX_CONFIG)
  103. using _STLP_VENDOR_CSTD::rand;
  104. using _STLP_VENDOR_CSTD::srand;
  105. # endif /* !_STLP_SGX_CONFIG */
  106. # endif /* _STLP_NO_CSTD_FUNCTION_IMPORTS */
  107. _STLP_END_NAMESPACE
  108. #endif /* _STLP_IMPORT_VENDOR_CSTD */
  109. #if (defined (__BORLANDC__) || defined (__WATCOMC__)) && defined (_STLP_USE_NEW_C_HEADERS)
  110. //In this config bcc define everything in std namespace and not in
  111. //the global one.
  112. inline int abs(int __x) { return _STLP_VENDOR_CSTD::abs(__x); }
  113. inline _STLP_VENDOR_CSTD::div_t div(int __x, int __y) { return _STLP_VENDOR_CSTD::div(__x, __y); }
  114. #endif
  115. #if defined(_MSC_EXTENSIONS) && defined(_STLP_MSVC) && (_STLP_MSVC <= 1300)
  116. # define _STLP_RESTORE_FUNCTION_INTRINSIC
  117. # pragma warning (push)
  118. # pragma warning (disable: 4162)
  119. # pragma function (abs)
  120. #endif
  121. //HP-UX native lib has abs() and div() functions in global namespace
  122. #if !defined (__SUNPRO_CC) && \
  123. (!defined (__HP_aCC) || (__HP_aCC < 30000))
  124. //MSVC starting with .Net 2003 already define all math functions in global namespace:
  125. # if defined (_STLP_SGX_CONFIG) || !defined (__WATCOMC__) && \
  126. (!defined (_STLP_MSVC_LIB) || (_STLP_MSVC_LIB < 1310) || defined (UNDER_CE))
  127. inline long abs(long __x) { return _STLP_VENDOR_CSTD::labs(__x); }
  128. # endif
  129. /** VC since version 8 has this, the platform SDK and CE SDKs hanging behind. */
  130. # if defined (_STLP_SGX_CONFIG) || !defined (__WATCOMC__) && \
  131. (!defined (_STLP_MSVC_LIB) || (_STLP_MSVC_LIB < 1400) || defined (_STLP_USING_PLATFORM_SDK_COMPILER) || defined (UNDER_CE))
  132. inline _STLP_VENDOR_CSTD::ldiv_t div(long __x, long __y) { return _STLP_VENDOR_CSTD::ldiv(__x, __y); }
  133. # endif
  134. #endif
  135. #if defined (_STLP_RESTORE_FUNCTION_INTRINSIC)
  136. # pragma intrinsic (abs)
  137. # pragma warning (pop)
  138. # undef _STLP_RESTORE_FUNCTION_INTRINSIC
  139. #endif
  140. #if defined (_STLP_LONG_LONG)
  141. # if !defined (_STLP_NO_VENDOR_STDLIB_L)
  142. # if !defined (__sun)
  143. inline _STLP_LONG_LONG abs(_STLP_LONG_LONG __x) { return _STLP_VENDOR_CSTD::llabs(__x); }
  144. inline lldiv_t div(_STLP_LONG_LONG __x, _STLP_LONG_LONG __y) { return _STLP_VENDOR_CSTD::lldiv(__x, __y); }
  145. # else
  146. inline _STLP_LONG_LONG abs(_STLP_LONG_LONG __x) { return ::llabs(__x); }
  147. inline lldiv_t div(_STLP_LONG_LONG __x, _STLP_LONG_LONG __y) { return ::lldiv(__x, __y); }
  148. # endif
  149. # else
  150. inline _STLP_LONG_LONG abs(_STLP_LONG_LONG __x) { return __x < 0 ? -__x : __x; }
  151. # endif
  152. #endif
  153. /* C++ Standard is unclear about several call to 'using ::func' if new overloads
  154. * of ::func appears between 2 successive 'using' calls. To avoid this potential
  155. * problem we provide all abs overload before the 'using' call.
  156. * Beware: This header inclusion has to be after all abs overload of this file.
  157. * The first 'using ::abs' call is going to be in the other header.
  158. */
  159. #ifndef _STLP_INTERNAL_CMATH
  160. # include <stl/_cmath.h>
  161. #endif
  162. #if defined (_STLP_IMPORT_VENDOR_CSTD) && !defined (_STLP_NO_CSTD_FUNCTION_IMPORTS)
  163. // ad hoc, don't replace with _STLP_VENDOR_CSTD::abs here! - ptr 2005-03-05
  164. _STLP_BEGIN_NAMESPACE
  165. using ::abs;
  166. using ::div;
  167. _STLP_END_NAMESPACE
  168. #endif
  169. #endif /* _STLP_INTERNAL_CSTDLIB */