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