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