Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / OS_NS_stdlib.h
blobbfa3ecb58f20d34cf633dbde34c37cf9483e52de
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file OS_NS_stdlib.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 * @author Jesper S. M|ller<stophph@diku.dk>
9 * @author and a cast of thousands...
11 //=============================================================================
13 #ifndef ACE_OS_NS_STDLIB_H
14 # define ACE_OS_NS_STDLIB_H
16 # include /**/ "ace/pre.h"
18 # include "ace/config-all.h"
20 # if !defined (ACE_LACKS_PRAGMA_ONCE)
21 # pragma once
22 # endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "ace/os_include/os_stdlib.h"
25 #include <cstdlib>
26 #include /**/ "ace/ACE_export.h"
28 #include "ace/Basic_Types.h" /* ACE_UINT64 and intptr_t in inl file */
30 #if defined (ACE_EXPORT_MACRO)
31 # undef ACE_EXPORT_MACRO
32 #endif
33 #define ACE_EXPORT_MACRO ACE_Export
35 // We need this for MVS... as well as Linux, etc...
36 // On Windows, we explicitly set this up as __cdecl so it's correct even
37 // if building with another calling convention, such as __stdcall.
38 #if defined (ACE_WIN32) && defined (_MSC_VER)
39 extern "C" {
40 typedef int (__cdecl *ACE_COMPARE_FUNC)(const void *, const void *);
42 #else
43 extern "C" {
44 typedef int (*ACE_COMPARE_FUNC)(const void *, const void *);
46 #endif /* ACE_WIN32 && _MSC_VER */
49 * We inline and undef some functions that may be implemented
50 * as macros on some platforms. This way macro definitions will
51 * be usable later as there is no way to save the macro definition
52 * using the pre-processor.
55 #if !defined (ACE_LACKS_STRTOLL) && !defined (ACE_STRTOLL_EQUIVALENT)
56 inline ACE_INT64 ace_strtoll_helper (const char *s, char **ptr, int base)
58 # if defined (strtoll)
59 return strtoll (s, ptr, base);
60 # undef strtoll
61 # else
62 return std::strtoll (s, ptr, base);
63 # endif /* strtoll */
65 #endif /* !ACE_LACKS_STRTOLL && !ACE_STRTOLL_EQUIVALENT */
67 #if !defined (ACE_LACKS_STRTOULL) && !defined (ACE_STRTOULL_EQUIVALENT)
68 inline ACE_INT64 ace_strtoull_helper (const char *s, char **ptr, int base)
70 # if defined (strtoull)
71 return strtoull (s, ptr, base);
72 # undef strtoull
73 # else
74 return std::strtoull (s, ptr, base);
75 # endif /* strtoull */
77 #endif /* !ACE_LACKS_STRTOULL && !ACE_STRTOULL_EQUIVALENT */
79 #if !defined (ACE_LACKS_RAND_R)
80 inline int ace_rand_r_helper (unsigned *seed)
82 # if defined (rand_r)
83 return rand_r (seed);
84 # undef rand_r
85 # else
86 return ACE_STD_NAMESPACE::rand_r (seed);
87 # endif /* rand_r */
89 #endif /* !ACE_LACKS_RAND_R */
91 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
93 namespace ACE_OS {
94 /** @name Non-standard functions
96 * These functions aren't in the standard.
99 //@{
100 ACE_NAMESPACE_INLINE_FUNCTION
101 void _exit [[noreturn]] (int status = 0);
103 ACE_NAMESPACE_INLINE_FUNCTION
104 void abort [[noreturn]] ();
107 * Register an at exit hook. The @a name can be used to analyze shutdown
108 * problems
110 ACE_NAMESPACE_INLINE_FUNCTION
111 int atexit (ACE_EXIT_HOOK func, const char* name = 0);
114 * Convert string to integer
116 ACE_NAMESPACE_INLINE_FUNCTION
117 int atoi (const char *s);
119 # if defined (ACE_HAS_WCHAR)
121 * Convert string to integer
123 ACE_NAMESPACE_INLINE_FUNCTION
124 int atoi (const wchar_t *s);
125 # endif /* ACE_HAS_WCHAR */
128 * Convert string to long
130 ACE_NAMESPACE_INLINE_FUNCTION
131 long atol (const char *s);
134 * Convert string to long
136 # if defined (ACE_HAS_WCHAR)
137 ACE_NAMESPACE_INLINE_FUNCTION
138 long atol (const wchar_t *s);
139 # endif /* ACE_HAS_WCHAR */
142 * Convert string to double
144 ACE_NAMESPACE_INLINE_FUNCTION
145 double atof (const char *s);
148 * Convert string to double
150 # if defined (ACE_HAS_WCHAR)
151 ACE_NAMESPACE_INLINE_FUNCTION
152 double atof (const wchar_t *s);
153 # endif /* ACE_HAS_WCHAR */
155 // atop not in spec
157 * Convert string to pointer
159 ACE_NAMESPACE_INLINE_FUNCTION
160 void *atop (const char *s);
162 # if defined (ACE_HAS_WCHAR)
164 * Convert string to pointer
166 ACE_NAMESPACE_INLINE_FUNCTION
167 void *atop (const wchar_t *s);
168 # endif /* ACE_HAS_WCHAR */
170 ACE_NAMESPACE_INLINE_FUNCTION
171 void *bsearch (const void *key,
172 const void *base,
173 size_t nel,
174 size_t size,
175 ACE_COMPARE_FUNC);
177 extern ACE_Export
178 void *calloc (size_t elements, size_t sizeof_elements);
180 extern ACE_Export
181 void exit [[noreturn]] (int status = 0);
183 extern ACE_Export
184 void free (void *);
186 ACE_NAMESPACE_INLINE_FUNCTION
187 char *getenv (const char *symbol);
189 # if defined (ACE_HAS_WCHAR) && defined (ACE_WIN32)
190 ACE_NAMESPACE_INLINE_FUNCTION
191 wchar_t *getenv (const wchar_t *symbol);
192 # endif /* ACE_HAS_WCHAR && ACE_WIN32 */
194 // not in spec
195 extern ACE_Export
196 ACE_TCHAR *getenvstrings ();
198 // itoa not in spec
199 /// Converts an integer to a string.
200 ACE_NAMESPACE_INLINE_FUNCTION
201 char *itoa (int value, char *string, int radix);
203 #if defined (ACE_HAS_WCHAR)
204 /// Converts an integer to a string.
205 ACE_NAMESPACE_INLINE_FUNCTION
206 wchar_t *itoa (int value, wchar_t *string, int radix);
207 #endif /* ACE_HAS_WCHAR */
209 #if !defined (ACE_HAS_ITOA)
210 /// Emulated itoa - Converts an integer to a string.
211 extern ACE_Export
212 char *itoa_emulation (int value, char *string, int radix);
213 #endif /* !ACE_HAS_ITOA */
215 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_ITOW)
216 /// Emulated itow - Converts an integer to a string.
217 extern ACE_Export
218 wchar_t *itow_emulation (int value, wchar_t *string, int radix);
219 #endif /* ACE_HAS_WCHAR && ACE_LACKS_ITOW */
221 extern ACE_Export
222 void *malloc (size_t);
224 ACE_NAMESPACE_INLINE_FUNCTION
225 ACE_HANDLE mkstemp (char *s);
227 # if defined (ACE_HAS_WCHAR)
228 ACE_NAMESPACE_INLINE_FUNCTION
229 ACE_HANDLE mkstemp (wchar_t *s);
230 # endif /* ACE_HAS_WCHAR */
232 #if defined (ACE_LACKS_MKSTEMP)
233 extern ACE_Export
234 ACE_HANDLE mkstemp_emulation (ACE_TCHAR * s);
235 #endif /* ACE_LACKS_MKSTEMP */
237 #if !defined (ACE_DISABLE_MKTEMP)
238 # if !defined (ACE_LACKS_MKTEMP)
239 ACE_NAMESPACE_INLINE_FUNCTION
240 char *mktemp (char *s);
242 # if defined (ACE_HAS_WCHAR)
243 ACE_NAMESPACE_INLINE_FUNCTION
244 wchar_t *mktemp (wchar_t *s);
245 # endif /* ACE_HAS_WCHAR */
246 # else
247 extern ACE_Export
248 ACE_TCHAR *mktemp (ACE_TCHAR *s);
249 # endif /* !ACE_LACKS_MKTEMP */
250 #endif /* !ACE_DISABLE_MKTEMP */
252 ACE_NAMESPACE_INLINE_FUNCTION
253 int putenv (const char *string);
255 #if defined (ACE_HAS_WCHAR) && defined (ACE_WIN32)
256 // Windows is the only platform that supports a wchar_t environment.
257 // Since other platforms make @a string part of the environment, it's
258 // a certain memory leak to copy and transform wchar_t to char for
259 // emulating this, so it's not attempted.
260 ACE_NAMESPACE_INLINE_FUNCTION
261 int putenv (const wchar_t *string);
262 #endif /* ACE_HAS_WCHAR && ACE_WIN32 */
264 ACE_NAMESPACE_INLINE_FUNCTION
265 void qsort (void *base,
266 size_t nel,
267 size_t width,
268 ACE_COMPARE_FUNC);
270 ACE_NAMESPACE_INLINE_FUNCTION
271 int setenv(const char *envname, const char *envval, int overwrite);
273 ACE_NAMESPACE_INLINE_FUNCTION
274 int unsetenv(const char *name);
276 ACE_NAMESPACE_INLINE_FUNCTION
277 int rand ();
279 ACE_NAMESPACE_INLINE_FUNCTION
280 int rand_r (unsigned int *seed);
282 extern ACE_Export
283 void *realloc (void *, size_t);
285 # if !defined (ACE_LACKS_REALPATH)
286 ACE_NAMESPACE_INLINE_FUNCTION
287 # else
288 extern ACE_Export
289 # endif /* !ACE_LACKS_REALPATH */
290 char *realpath (const char *file_name, char *resolved_name);
292 # if defined (ACE_HAS_WCHAR)
293 ACE_NAMESPACE_INLINE_FUNCTION
294 wchar_t *realpath (const wchar_t *file_name, wchar_t *resolved_name);
295 # endif /* ACE_HAS_WCHAR */
297 // exit_hook and set_exit_hook not in spec
298 /// Function that is called by <ACE_OS::exit>, if non-null.
299 extern ACE_Export ACE_EXIT_HOOK exit_hook_;
301 /// For use by ACE_Object_Manager only, to register its exit hook..
302 ACE_NAMESPACE_INLINE_FUNCTION
303 ACE_EXIT_HOOK set_exit_hook (ACE_EXIT_HOOK hook);
305 ACE_NAMESPACE_INLINE_FUNCTION
306 void srand (u_int seed);
308 // not in spec
309 extern ACE_Export
310 ACE_TCHAR *strenvdup (const ACE_TCHAR *str);
312 /// Converts a string to a double value (char version).
313 ACE_NAMESPACE_INLINE_FUNCTION
314 double strtod (const char *s, char **endptr);
316 #if defined (ACE_HAS_WCHAR) && !defined (ACE_LACKS_WCSTOD)
317 /// Converts a string to a double value (wchar_t version).
318 ACE_NAMESPACE_INLINE_FUNCTION
319 double strtod (const wchar_t *s, wchar_t **endptr);
320 #endif /* ACE_HAS_WCHAR && !ACE_LACKS_WCSTOD */
322 /// Converts a string to a long value (char version).
323 ACE_NAMESPACE_INLINE_FUNCTION
324 long strtol (const char *s, char **ptr, int base);
326 #if defined (ACE_LACKS_STRTOL)
327 extern ACE_Export
328 long strtol_emulation (const char *nptr, char **endptr, int base);
329 #endif /* ACE_LACKS_STRTOL */
331 #if defined (ACE_HAS_WCHAR)
332 /// Converts a string to a long value (wchar_t version).
333 ACE_NAMESPACE_INLINE_FUNCTION
334 long strtol (const wchar_t *s, wchar_t **ptr, int base);
336 #if defined (ACE_LACKS_WCSTOL)
337 extern ACE_Export
338 long wcstol_emulation (const wchar_t *nptr, wchar_t **endptr, int base);
339 #endif /* ACE_LACKS_WCSTOL */
341 #endif /* ACE_HAS_WCHAR */
343 /// Converts a string to an unsigned long value (char version).
344 ACE_NAMESPACE_INLINE_FUNCTION
345 unsigned long strtoul (const char *s, char **ptr, int base);
347 #if defined (ACE_LACKS_STRTOUL)
348 extern ACE_Export
349 unsigned long strtoul_emulation (const char *nptr,
350 char **endptr,
351 int base);
352 #endif /* ACE_LACKS_STRTOUL */
354 #if defined (ACE_HAS_WCHAR)
355 /// Converts a string to an unsigned long value (wchar_t version).
356 ACE_NAMESPACE_INLINE_FUNCTION
357 unsigned long strtoul (const wchar_t *s, wchar_t **ptr, int base);
359 #if defined (ACE_LACKS_WCSTOUL)
360 extern ACE_Export
361 unsigned long wcstoul_emulation (const wchar_t *nptr,
362 wchar_t **endptr,
363 int base);
364 #endif /* ACE_LACKS_WCSTOUL */
366 #endif /* ACE_HAS_WCHAR */
368 /// Converts a string to a signed 64 bit int value (char version).
369 ACE_NAMESPACE_INLINE_FUNCTION
370 ACE_INT64 strtoll (const char *s, char **ptr, int base);
372 #if defined (ACE_LACKS_STRTOLL)
373 extern ACE_Export
374 ACE_INT64 strtoll_emulation (const char *nptr,
375 char **endptr,
376 int base);
377 #endif /* ACE_LACKS_STRTOLL */
379 #if defined (ACE_HAS_WCHAR)
380 /// Converts a string to a signed 64 bit int value (wchar_t version).
381 ACE_NAMESPACE_INLINE_FUNCTION
382 ACE_INT64 strtoll (const wchar_t *s, wchar_t **ptr, int base);
384 #if defined (ACE_LACKS_WCSTOLL)
385 extern ACE_Export
386 ACE_INT64 wcstoll_emulation (const wchar_t *nptr,
387 wchar_t **endptr,
388 int base);
389 #endif /* ACE_LACKS_WCSTOLL */
391 #endif /* ACE_HAS_WCHAR */
393 /// Converts a string to a unsigned 64 bit int value (char version).
394 ACE_NAMESPACE_INLINE_FUNCTION
395 ACE_UINT64 strtoull (const char *s, char **ptr, int base);
397 #if defined (ACE_LACKS_STRTOULL)
398 extern ACE_Export
399 ACE_UINT64 strtoull_emulation (const char *nptr,
400 char **endptr,
401 int base);
402 #endif /* ACE_LACKS_STRTOULL */
404 #if defined (ACE_HAS_WCHAR)
405 /// Converts a string to a unsigned 64 bit int value (wchar_t version).
406 ACE_NAMESPACE_INLINE_FUNCTION
407 ACE_UINT64 strtoull (const wchar_t *s, wchar_t **ptr, int base);
409 #if defined (ACE_LACKS_WCSTOULL)
410 extern ACE_Export
411 ACE_UINT64 wcstoull_emulation (const wchar_t *nptr,
412 wchar_t **endptr,
413 int base);
414 #endif /* ACE_LACKS_WCSTOULL */
416 #endif /* ACE_HAS_WCHAR */
418 ACE_NAMESPACE_INLINE_FUNCTION
419 int system (const ACE_TCHAR *s);
421 /// Get the name of the current program
423 /// Originally from NetBSD, now found in *BSD, Cygwin, Darwin, etc.
424 ACE_NAMESPACE_INLINE_FUNCTION
425 const char *getprogname ();
427 #if !defined (ACE_HAS_GETPROGNAME)
428 extern ACE_Export
429 const char *getprogname_emulation ();
430 #endif /* !ACE_HAS_GETPROGNAME */
432 /// Set the name of the current program
434 /// Originally from NetBSD, now found in *BSD, Cygwin, Darwin, etc.
435 ACE_NAMESPACE_INLINE_FUNCTION
436 void setprogname (const char* name);
438 #if !defined (ACE_HAS_SETPROGNAME)
439 extern ACE_Export
440 void setprogname_emulation (const char* name);
441 #endif /* !ACE_HAS_SETPROGNAME */
443 } /* namespace ACE_OS */
445 ACE_END_VERSIONED_NAMESPACE_DECL
447 # if defined (ACE_HAS_INLINED_OSCALLS)
448 # if defined (ACE_INLINE)
449 # undef ACE_INLINE
450 # endif /* ACE_INLINE */
451 # define ACE_INLINE inline
452 # include "ace/OS_NS_stdlib.inl"
453 # endif /* ACE_HAS_INLINED_OSCALLS */
455 # include /**/ "ace/post.h"
456 #endif /* ACE_OS_NS_STDLIB_H */