]> git.saurik.com Git - wxWidgets.git/blame - include/wx/wxcrtbase.h
support for simulating focus events since not all controls can be focused
[wxWidgets.git] / include / wx / wxcrtbase.h
CommitLineData
eb9524ca
VS
1/*
2 * Name: wx/wxcrtbase.h
3 * Purpose: Type-safe ANSI and Unicode builds compatible wrappers for
4 * CRT functions
9d55bfef 5 * Author: Joel Farley, Ove Kaaven
eb9524ca
VS
6 * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee
7 * Created: 1998/06/12
8 * RCS-ID: $Id$
9 * Copyright: (c) 1998-2006 wxWidgets dev team
10 * Licence: wxWindows licence
11 */
12
13/* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
14
15#ifndef _WX_WXCRTBASE_H_
16#define _WX_WXCRTBASE_H_
17
18/* -------------------------------------------------------------------------
19 headers and missing declarations
20 ------------------------------------------------------------------------- */
21
22#include "wx/chartype.h"
23
24/*
25 Standard headers we need here.
26
27 NB: don't include any wxWidgets headers here because almost all of them
28 include this one!
03647350 29
b7d70f76
FM
30 NB2: User code should include wx/crt.h instead of including this
31 header directly.
32
eb9524ca
VS
33 */
34
35#include <stdio.h>
36#include <string.h>
37#include <ctype.h>
bd362275 38#include <wctype.h>
eb9524ca
VS
39#include <time.h>
40
d6f2a891
VZ
41#if defined(__WINDOWS__) && !defined(__WXWINCE__)
42 #include <io.h>
4e0a0557 43#endif
eb9524ca
VS
44
45#if defined(HAVE_STRTOK_R) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
46 char *strtok_r(char *, const char *, char **);
47#endif
48
f030eeed
VZ
49/*
50 Using -std=c++{98,0x} option with mingw32 disables most of standard
51 library extensions, so we can't rely on the presence of common non-ANSI
52 functions, define a special symbol to test for this. Notice that this
53 doesn't need to be done for g++ under Linux where _GNU_SOURCE (which is
54 defined by default) still makes all common extensions available even in
55 ANSI mode.
56 */
57#if defined(__MINGW32__) && defined(__STRICT_ANSI__)
58 #define __WX_STRICT_ANSI_GCC__
59#endif
60
eb9524ca
VS
61/*
62 a few compilers don't have the (non standard but common) isascii function,
63 define it ourselves for them
64 */
65#ifndef isascii
2415cf67 66 #if defined(__WX_STRICT_ANSI_GCC__)
eb9524ca
VS
67 #define wxNEED_ISASCII
68 #elif defined(_WIN32_WCE)
69 #if _WIN32_WCE <= 211
70 #define wxNEED_ISASCII
71 #endif
72 #endif
73#endif /* isascii */
74
75#ifdef wxNEED_ISASCII
76 inline int isascii(int c) { return (unsigned)c < 0x80; }
77#endif
78
79#ifdef _WIN32_WCE
80 #if _WIN32_WCE <= 211
9a83f860 81 #define isspace(c) ((c) == wxT(' ') || (c) == wxT('\t'))
eb9524ca
VS
82 #endif
83#endif /* _WIN32_WCE */
84
85/* string.h functions */
86#ifndef strdup
2415cf67 87 #if defined(__WXWINCE__)
eb9524ca
VS
88 #if _WIN32_WCE <= 211
89 #define wxNEED_STRDUP
90 #endif
91 #endif
92#endif /* strdup */
93
94#ifdef wxNEED_STRDUP
95 WXDLLIMPEXP_BASE char *strdup(const char* s);
96#endif
97
98/* missing functions in some WinCE versions */
99#ifdef _WIN32_WCE
100#if (_WIN32_WCE < 300)
101WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size );
102#endif
103#endif /* _WIN32_WCE */
104
105
eb9524ca
VS
106/* -------------------------------------------------------------------------
107 UTF-8 locale handling
108 ------------------------------------------------------------------------- */
109
110#ifdef __cplusplus
111 #if wxUSE_UNICODE_UTF8
28efe654
VS
112 /* flag indicating whether the current locale uses UTF-8 or not; must be
113 updated every time the locale is changed! */
eb9524ca
VS
114 #if wxUSE_UTF8_LOCALE_ONLY
115 #define wxLocaleIsUtf8 true
116 #else
117 extern WXDLLIMPEXP_BASE bool wxLocaleIsUtf8;
118 #endif
28efe654 119 /* function used to update the flag: */
eb9524ca 120 extern WXDLLIMPEXP_BASE void wxUpdateLocaleIsUtf8();
28efe654 121 #else /* !wxUSE_UNICODE_UTF8 */
eb9524ca 122 inline void wxUpdateLocaleIsUtf8() {}
28efe654
VS
123 #endif /* wxUSE_UNICODE_UTF8/!wxUSE_UNICODE_UTF8 */
124#endif /* __cplusplus */
eb9524ca
VS
125
126
127/* -------------------------------------------------------------------------
128 string.h
129 ------------------------------------------------------------------------- */
130
131#define wxCRT_StrcatA strcat
132#define wxCRT_StrchrA strchr
133#define wxCRT_StrcmpA strcmp
eb9524ca
VS
134#define wxCRT_StrcpyA strcpy
135#define wxCRT_StrcspnA strcspn
136#define wxCRT_StrlenA strlen
137#define wxCRT_StrncatA strncat
138#define wxCRT_StrncmpA strncmp
139#define wxCRT_StrncpyA strncpy
140#define wxCRT_StrpbrkA strpbrk
141#define wxCRT_StrrchrA strrchr
142#define wxCRT_StrspnA strspn
143#define wxCRT_StrstrA strstr
eb9524ca 144
410390cf
VS
145#define wxCRT_StrcatW wcscat
146#define wxCRT_StrchrW wcschr
147#define wxCRT_StrcmpW wcscmp
410390cf
VS
148#define wxCRT_StrcpyW wcscpy
149#define wxCRT_StrcspnW wcscspn
150#define wxCRT_StrncatW wcsncat
151#define wxCRT_StrncmpW wcsncmp
152#define wxCRT_StrncpyW wcsncpy
153#define wxCRT_StrpbrkW wcspbrk
154#define wxCRT_StrrchrW wcsrchr
155#define wxCRT_StrspnW wcsspn
156#define wxCRT_StrstrW wcsstr
d6f2a891
VZ
157
158/* these functions are not defined under CE, at least in VC8 CRT */
bd362275 159#if !defined(__WXWINCE__)
d6f2a891
VZ
160 #define wxCRT_StrcollA strcoll
161 #define wxCRT_StrxfrmA strxfrm
162
163 #define wxCRT_StrcollW wcscoll
164 #define wxCRT_StrxfrmW wcsxfrm
165#endif /* __WXWINCE__ */
410390cf 166
2415cf67
VZ
167/* Almost all compiler have strdup(), but VC++ for CE doesn't provide it.
168 Another special case is gcc in strict ANSI mode: normally it doesn't provide
169 strdup() but MinGW does provide it under MSVC-compatible name so test for it
170 before checking __WX_STRICT_ANSI_GCC__. */
adfbce4f
VZ
171#if (defined(__VISUALC__) && __VISUALC__ >= 1400) || \
172 defined(__MINGW32__)
410390cf 173 #define wxCRT_StrdupA _strdup
2415cf67 174#elif !(defined(__WXWINCE__) || defined(__WX_STRICT_ANSI_GCC__))
410390cf
VS
175 #define wxCRT_StrdupA strdup
176#endif
4691b518 177
e78c47e3 178/* most Windows compilers provide _wcsdup() */
f030eeed
VZ
179#if defined(__WINDOWS__) && \
180 !(defined(__CYGWIN__) || defined(__WX_STRICT_ANSI_GCC__))
410390cf 181 #define wxCRT_StrdupW _wcsdup
8a02058a 182#elif defined(HAVE_WCSDUP)
410390cf 183 #define wxCRT_StrdupW wcsdup
eb9524ca
VS
184#endif
185
186#ifdef wxHAVE_TCHAR_SUPPORT
187 /* we surely have wchar_t if we have TCHAR have wcslen() */
188 #ifndef HAVE_WCSLEN
189 #define HAVE_WCSLEN
190 #endif
191#endif /* wxHAVE_TCHAR_SUPPORT */
192
193#ifdef HAVE_WCSLEN
194 #define wxCRT_StrlenW wcslen
195#endif
196
197#define wxCRT_StrtodA strtod
198#define wxCRT_StrtolA strtol
199#define wxCRT_StrtoulA strtoul
200#define wxCRT_StrtodW wcstod
201#define wxCRT_StrtolW wcstol
202#define wxCRT_StrtoulW wcstoul
203
204#ifdef __VISUALC__
205 #if __VISUALC__ >= 1300 && !defined(__WXWINCE__)
206 #define wxCRT_StrtollA _strtoi64
207 #define wxCRT_StrtoullA _strtoui64
208 #define wxCRT_StrtollW _wcstoi64
209 #define wxCRT_StrtoullW _wcstoui64
210 #endif /* VC++ 7+ */
211#else
212 #ifdef HAVE_STRTOULL
213 #define wxCRT_StrtollA strtoll
214 #define wxCRT_StrtoullA strtoull
215 #endif /* HAVE_STRTOULL */
216 #ifdef HAVE_WCSTOULL
217 /* assume that we have wcstoull(), which is also C99, too */
218 #define wxCRT_StrtollW wcstoll
219 #define wxCRT_StrtoullW wcstoull
220 #endif /* HAVE_WCSTOULL */
221#endif
222
951f792f
VZ
223/*
224 Only VC8 and later provide strnlen() and wcsnlen() functions under Windows
225 and it's also only available starting from Windows CE 6.0 only in CE build.
226 */
16d2c3ea 227#if wxCHECK_VISUALC_VERSION(8) && (!defined(_WIN32_WCE) || (_WIN32_WCE >= 0x600))
951f792f
VZ
228 #ifndef HAVE_STRNLEN
229 #define HAVE_STRNLEN
230 #endif
231 #ifndef HAVE_WCSNLEN
232 #define HAVE_WCSNLEN
233 #endif
234#endif
235
236#ifdef HAVE_STRNLEN
f1b63efe 237 #define wxCRT_StrnlenA strnlen
7c5ac499
FM
238#endif
239
951f792f 240#ifdef HAVE_WCSNLEN
f1b63efe
FM
241 #define wxCRT_StrnlenW wcsnlen
242#endif
eb9524ca
VS
243
244/* define wxCRT_StricmpA/W and wxCRT_StrnicmpA/W for various compilers */
245
6689960c
VZ
246#if defined(__BORLANDC__) || defined(__WATCOMC__) || \
247 defined(__VISAGECPP__) || \
248 defined(__EMX__) || defined(__DJGPP__)
249 #define wxCRT_StricmpA stricmp
250 #define wxCRT_StrnicmpA strnicmp
2415cf67 251#elif defined(__SYMANTEC__) || defined(__VISUALC__)
6689960c
VZ
252 #define wxCRT_StricmpA _stricmp
253 #define wxCRT_StrnicmpA _strnicmp
f030eeed 254#elif defined(__UNIX__) || (defined(__GNUWIN32__) && !defined(__WX_STRICT_ANSI_GCC__))
6689960c
VZ
255 #define wxCRT_StricmpA strcasecmp
256 #define wxCRT_StrnicmpA strncasecmp
257/* #else -- use wxWidgets implementation */
258#endif
259
260#ifdef __VISUALC__
261 #define wxCRT_StricmpW _wcsicmp
262 #define wxCRT_StrnicmpW _wcsnicmp
263#elif defined(__UNIX__)
264 #ifdef HAVE_WCSCASECMP
265 #define wxCRT_StricmpW wcscasecmp
eb9524ca 266 #endif
6689960c
VZ
267 #ifdef HAVE_WCSNCASECMP
268 #define wxCRT_StrnicmpW wcsncasecmp
269 #endif
270/* #else -- use wxWidgets implementation */
271#endif
eb9524ca
VS
272
273#ifdef HAVE_STRTOK_R
274 #define wxCRT_StrtokA(str, sep, last) strtok_r(str, sep, last)
275#endif
276/* FIXME-UTF8: detect and use wcstok() if available for wxCRT_StrtokW */
277
278/* these are extern "C" because they are used by regex lib: */
279#ifdef __cplusplus
280extern "C" {
281#endif
282
283#ifndef wxCRT_StrlenW
284WXDLLIMPEXP_BASE size_t wxCRT_StrlenW(const wchar_t *s);
285#endif
286
287#ifndef wxCRT_StrncmpW
288WXDLLIMPEXP_BASE int wxCRT_StrncmpW(const wchar_t *s1, const wchar_t *s2, size_t n);
289#endif
290
291#ifdef __cplusplus
292}
293#endif
294
295/* FIXME-UTF8: remove this once we are Unicode only */
296#if wxUSE_UNICODE
297 #define wxCRT_StrlenNative wxCRT_StrlenW
298 #define wxCRT_StrncmpNative wxCRT_StrncmpW
299 #define wxCRT_ToupperNative wxCRT_ToupperW
300 #define wxCRT_TolowerNative wxCRT_TolowerW
301#else
302 #define wxCRT_StrlenNative wxCRT_StrlenA
303 #define wxCRT_StrncmpNative wxCRT_StrncmpA
304 #define wxCRT_ToupperNative toupper
305 #define wxCRT_TolowerNative tolower
306#endif
307
308#ifndef wxCRT_StrcatW
309WXDLLIMPEXP_BASE wchar_t *wxCRT_StrcatW(wchar_t *dest, const wchar_t *src);
310#endif
311
312#ifndef wxCRT_StrchrW
313WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrchrW(const wchar_t *s, wchar_t c);
314#endif
315
316#ifndef wxCRT_StrcmpW
317WXDLLIMPEXP_BASE int wxCRT_StrcmpW(const wchar_t *s1, const wchar_t *s2);
318#endif
319
320#ifndef wxCRT_StrcollW
321WXDLLIMPEXP_BASE int wxCRT_StrcollW(const wchar_t *s1, const wchar_t *s2);
322#endif
323
324#ifndef wxCRT_StrcpyW
325WXDLLIMPEXP_BASE wchar_t *wxCRT_StrcpyW(wchar_t *dest, const wchar_t *src);
326#endif
327
328#ifndef wxCRT_StrcspnW
329WXDLLIMPEXP_BASE size_t wxCRT_StrcspnW(const wchar_t *s, const wchar_t *reject);
330#endif
331
332#ifndef wxCRT_StrncatW
333WXDLLIMPEXP_BASE wchar_t *wxCRT_StrncatW(wchar_t *dest, const wchar_t *src, size_t n);
334#endif
335
336#ifndef wxCRT_StrncpyW
337WXDLLIMPEXP_BASE wchar_t *wxCRT_StrncpyW(wchar_t *dest, const wchar_t *src, size_t n);
338#endif
339
340#ifndef wxCRT_StrpbrkW
341WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrpbrkW(const wchar_t *s, const wchar_t *accept);
342#endif
343
344#ifndef wxCRT_StrrchrW
345WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrrchrW(const wchar_t *s, wchar_t c);
346#endif
347
348#ifndef wxCRT_StrspnW
349WXDLLIMPEXP_BASE size_t wxCRT_StrspnW(const wchar_t *s, const wchar_t *accept);
350#endif
351
352#ifndef wxCRT_StrstrW
353WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrstrW(const wchar_t *haystack, const wchar_t *needle);
354#endif
355
356#ifndef wxCRT_StrtodW
357WXDLLIMPEXP_BASE double wxCRT_StrtodW(const wchar_t *nptr, wchar_t **endptr);
358#endif
359
360#ifndef wxCRT_StrtolW
361WXDLLIMPEXP_BASE long int wxCRT_StrtolW(const wchar_t *nptr, wchar_t **endptr, int base);
362#endif
363
364#ifndef wxCRT_StrtoulW
365WXDLLIMPEXP_BASE unsigned long int wxCRT_StrtoulW(const wchar_t *nptr, wchar_t **endptr, int base);
366#endif
367
368#ifndef wxCRT_StrxfrmW
369WXDLLIMPEXP_BASE size_t wxCRT_StrxfrmW(wchar_t *dest, const wchar_t *src, size_t n);
370#endif
371
372#ifndef wxCRT_StrdupA
373WXDLLIMPEXP_BASE char *wxCRT_StrdupA(const char *psz);
374#endif
375
376#ifndef wxCRT_StrdupW
377WXDLLIMPEXP_BASE wchar_t *wxCRT_StrdupW(const wchar_t *pwz);
378#endif
379
380#ifndef wxCRT_StricmpA
381WXDLLIMPEXP_BASE int wxCRT_StricmpA(const char *psz1, const char *psz2);
382#endif
383
384#ifndef wxCRT_StricmpW
385WXDLLIMPEXP_BASE int wxCRT_StricmpW(const wchar_t *psz1, const wchar_t *psz2);
386#endif
387
388#ifndef wxCRT_StrnicmpA
389WXDLLIMPEXP_BASE int wxCRT_StrnicmpA(const char *psz1, const char *psz2, size_t len);
390#endif
391
392#ifndef wxCRT_StrnicmpW
393WXDLLIMPEXP_BASE int wxCRT_StrnicmpW(const wchar_t *psz1, const wchar_t *psz2, size_t len);
394#endif
395
396#ifndef wxCRT_StrtokA
397WXDLLIMPEXP_BASE char *wxCRT_StrtokA(char *psz, const char *delim, char **save_ptr);
398#endif
399
400#ifndef wxCRT_StrtokW
401WXDLLIMPEXP_BASE wchar_t *wxCRT_StrtokW(wchar_t *psz, const wchar_t *delim, wchar_t **save_ptr);
402#endif
403
404/* supply strtoll and strtoull, if needed */
bdcb2137
VS
405#ifdef wxLongLong_t
406 #ifndef wxCRT_StrtollA
407 WXDLLIMPEXP_BASE wxLongLong_t wxCRT_StrtollA(const char* nptr,
408 char** endptr,
409 int base);
410 WXDLLIMPEXP_BASE wxULongLong_t wxCRT_StrtoullA(const char* nptr,
411 char** endptr,
412 int base);
413 #endif
414 #ifndef wxCRT_StrtollW
415 WXDLLIMPEXP_BASE wxLongLong_t wxCRT_StrtollW(const wchar_t* nptr,
416 wchar_t** endptr,
417 int base);
418 WXDLLIMPEXP_BASE wxULongLong_t wxCRT_StrtoullW(const wchar_t* nptr,
419 wchar_t** endptr,
420 int base);
421 #endif
e78c47e3 422#endif /* wxLongLong_t */
eb9524ca
VS
423
424
425/* -------------------------------------------------------------------------
426 stdio.h
427 ------------------------------------------------------------------------- */
428
bd362275 429#if defined(__UNIX__) || defined(__WXMAC__)
eb9524ca
VS
430 #define wxMBFILES 1
431#else
432 #define wxMBFILES 0
433#endif
434
435
436/* these functions are only needed in the form used for filenames (i.e. char*
437 on Unix, wchar_t* on Windows), so we don't need to use A/W suffix: */
28efe654 438#if wxMBFILES || !wxUSE_UNICODE /* ANSI filenames */
eb9524ca
VS
439
440 #define wxCRT_Fopen fopen
441 #define wxCRT_Freopen freopen
442 #define wxCRT_Remove remove
443 #define wxCRT_Rename rename
444
28efe654 445#else /* Unicode filenames */
eb9524ca
VS
446 /* special case: these functions are missing under Win9x with Unicows so we
447 have to implement them ourselves */
f030eeed 448 #if wxUSE_UNICODE_MSLU || defined(__WX_STRICT_ANSI_GCC__)
eb9524ca
VS
449 WXDLLIMPEXP_BASE FILE* wxMSLU__wfopen(const wchar_t *name, const wchar_t *mode);
450 WXDLLIMPEXP_BASE FILE* wxMSLU__wfreopen(const wchar_t *name, const wchar_t *mode, FILE *stream);
451 WXDLLIMPEXP_BASE int wxMSLU__wrename(const wchar_t *oldname, const wchar_t *newname);
452 WXDLLIMPEXP_BASE int wxMSLU__wremove(const wchar_t *name);
453 #define wxCRT_Fopen wxMSLU__wfopen
a007b626 454 #define wxCRT_Freopen wxMSLU__wfreopen
eb9524ca
VS
455 #define wxCRT_Remove wxMSLU__wremove
456 #define wxCRT_Rename wxMSLU__wrename
457 #else
d6f2a891 458 /* WinCE CRT doesn't provide these functions so use our own */
eb9524ca 459 #ifdef __WXWINCE__
d6f2a891
VZ
460 WXDLLIMPEXP_BASE int wxCRT_Rename(const wchar_t *src,
461 const wchar_t *dst);
462 WXDLLIMPEXP_BASE int wxCRT_Remove(const wchar_t *path);
eb9524ca 463 #else
d6f2a891 464 #define wxCRT_Rename _wrename
eb9524ca
VS
465 #define wxCRT_Remove _wremove
466 #endif
d6f2a891
VZ
467 #define wxCRT_Fopen _wfopen
468 #define wxCRT_Freopen _wfreopen
eb9524ca
VS
469 #endif
470
28efe654 471#endif /* wxMBFILES/!wxMBFILES */
eb9524ca
VS
472
473#define wxCRT_PutsA puts
474#define wxCRT_FputsA fputs
475#define wxCRT_FgetsA fgets
476#define wxCRT_FputcA fputc
477#define wxCRT_FgetcA fgetc
478#define wxCRT_UngetcA ungetc
479
410390cf
VS
480#ifdef wxHAVE_TCHAR_SUPPORT
481 #define wxCRT_PutsW _putws
482 #define wxCRT_FputsW fputws
483 #define wxCRT_FputcW fputwc
484#endif
485#ifdef HAVE_FPUTWS
486 #define wxCRT_FputsW fputws
487#endif
488#ifdef HAVE_PUTWS
489 #define wxCRT_PutsW putws
490#endif
491#ifdef HAVE_FPUTWC
492 #define wxCRT_FputcW fputwc
493#endif
494#define wxCRT_FgetsW fgetws
eb9524ca
VS
495
496#ifndef wxCRT_PutsW
497WXDLLIMPEXP_BASE int wxCRT_PutsW(const wchar_t *ws);
498#endif
499
500#ifndef wxCRT_FputsW
501WXDLLIMPEXP_BASE int wxCRT_FputsW(const wchar_t *ch, FILE *stream);
502#endif
503
504#ifndef wxCRT_FputcW
505WXDLLIMPEXP_BASE int wxCRT_FputcW(wchar_t wc, FILE *stream);
506#endif
507
57e2b887
VS
508/*
509 NB: tmpnam() is unsafe and thus is not wrapped!
510 Use other wxWidgets facilities instead:
511 wxFileName::CreateTempFileName, wxTempFile, or wxTempFileOutputStream
512*/
513#define wxTmpnam(x) wxTmpnam_is_insecure_use_wxTempFile_instead
eb9524ca 514
d6f2a891
VZ
515/* FIXME-CE: provide our own perror() using ::GetLastError() */
516#ifndef __WXWINCE__
517
eb9524ca
VS
518#define wxCRT_PerrorA perror
519#ifdef wxHAVE_TCHAR_SUPPORT
520 #define wxCRT_PerrorW _wperror
521#endif
522
d6f2a891
VZ
523#endif /* !__WXWINCE__ */
524
eb9524ca
VS
525/* -------------------------------------------------------------------------
526 stdlib.h
527 ------------------------------------------------------------------------- */
528
529/* there are no env vars at all under CE, so no _tgetenv neither */
530#ifdef __WXWINCE__
531 /* can't define as inline function as this is a C file... */
d6f2a891
VZ
532 #define wxCRT_GetenvA(name) (name, NULL)
533 #define wxCRT_GetenvW(name) (name, NULL)
eb9524ca
VS
534#else
535 #define wxCRT_GetenvA getenv
536 #ifdef _tgetenv
537 #define wxCRT_GetenvW _wgetenv
538 #endif
539#endif
540
541#ifndef wxCRT_GetenvW
542WXDLLIMPEXP_BASE wchar_t * wxCRT_GetenvW(const wchar_t *name);
543#endif
544
545
546#define wxCRT_SystemA system
547/* mingw32 doesn't provide _tsystem() or _wsystem(): */
548#if defined(_tsystem)
549 #define wxCRT_SystemW _wsystem
550#endif
551
552#define wxCRT_AtofA atof
553#define wxCRT_AtoiA atoi
554#define wxCRT_AtolA atol
555
2415cf67 556#if defined(wxHAVE_TCHAR_SUPPORT) && !defined(__WX_STRICT_ANSI_GCC__)
eb9524ca
VS
557 #define wxCRT_AtoiW _wtoi
558 #define wxCRT_AtolW _wtol
559 /* _wtof doesn't exist */
560#else
28ffb1f2 561#ifndef __VMS
5c15fb21 562 #define wxCRT_AtofW(s) wcstod(s, NULL)
28ffb1f2 563#endif
eb9524ca
VS
564 #define wxCRT_AtolW(s) wcstol(s, NULL, 10)
565 /* wcstoi doesn't exist */
566#endif
567
eb9524ca 568#ifdef __DARWIN__
26632ccd 569 #if !defined(__WXOSX_IPHONE__) && MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2
eb9524ca
VS
570 #define wxNEED_WX_MBSTOWCS
571 #endif
572#endif
573
574#ifdef wxNEED_WX_MBSTOWCS
575 /* even though they are defined and "implemented", they are bad and just
576 stubs so we need our own - we need these even in ANSI builds!! */
577 WXDLLIMPEXP_BASE size_t wxMbstowcs(wchar_t *, const char *, size_t);
578 WXDLLIMPEXP_BASE size_t wxWcstombs(char *, const wchar_t *, size_t);
579#else
580 #define wxMbstowcs mbstowcs
581 #define wxWcstombs wcstombs
582#endif
583
584
585
586/* -------------------------------------------------------------------------
587 time.h
588 ------------------------------------------------------------------------- */
589
590#define wxCRT_StrftimeA strftime
d0204fee
VZ
591#ifdef __SGI__
592 /*
593 IRIX provides not one but two versions of wcsftime(): XPG4 one which
594 uses "const char*" for the third parameter and so can't be used and the
595 correct, XPG5, one. Unfortunately we can't just define _XOPEN_SOURCE
596 high enough to get XPG5 version as this undefines other symbols which
597 make other functions we use unavailable (see <standards.h> for gory
598 details). So just declare the XPG5 version ourselves, we're extremely
599 unlikely to ever be compiled on a system without it. But if we ever do,
600 a configure test would need to be added for it (and _MIPS_SYMBOL_PRESENT
601 should be used to check for its presence during run-time, i.e. it would
602 probably be simpler to just always use our own wxCRT_StrftimeW() below
603 if it does ever become a problem).
604 */
a89c31bb
PC
605#ifdef __cplusplus
606 extern "C"
607#endif
608 size_t
d0204fee
VZ
609 _xpg5_wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm * );
610 #define wxCRT_StrftimeW _xpg5_wcsftime
611#else
e78c47e3 612 /*
bd362275
VZ
613 Assume it's always available under non-Unix systems as this does seem
614 to be the case for now. And under Unix we trust configure to detect it
615 (except for SGI special case above).
e78c47e3 616 */
bd362275 617 #if defined(HAVE_WCSFTIME) || !defined(__UNIX__)
d0204fee 618 #define wxCRT_StrftimeW wcsftime
bd362275 619 #endif
d0204fee 620#endif
eb9524ca
VS
621
622#ifndef wxCRT_StrftimeW
623WXDLLIMPEXP_BASE size_t wxCRT_StrftimeW(wchar_t *s, size_t max,
624 const wchar_t *fmt,
625 const struct tm *tm);
626#endif
627
628
629
630/* -------------------------------------------------------------------------
631 ctype.h
632 ------------------------------------------------------------------------- */
633
eb9524ca
VS
634#ifdef __WATCOMC__
635 #define WXWCHAR_T_CAST(c) (wint_t)(c)
636#else
637 #define WXWCHAR_T_CAST(c) c
638#endif
639
410390cf
VS
640#define wxCRT_IsalnumW(c) iswalnum(WXWCHAR_T_CAST(c))
641#define wxCRT_IsalphaW(c) iswalpha(WXWCHAR_T_CAST(c))
642#define wxCRT_IscntrlW(c) iswcntrl(WXWCHAR_T_CAST(c))
643#define wxCRT_IsdigitW(c) iswdigit(WXWCHAR_T_CAST(c))
644#define wxCRT_IsgraphW(c) iswgraph(WXWCHAR_T_CAST(c))
645#define wxCRT_IslowerW(c) iswlower(WXWCHAR_T_CAST(c))
646#define wxCRT_IsprintW(c) iswprint(WXWCHAR_T_CAST(c))
647#define wxCRT_IspunctW(c) iswpunct(WXWCHAR_T_CAST(c))
648#define wxCRT_IsspaceW(c) iswspace(WXWCHAR_T_CAST(c))
649#define wxCRT_IsupperW(c) iswupper(WXWCHAR_T_CAST(c))
650#define wxCRT_IsxdigitW(c) iswxdigit(WXWCHAR_T_CAST(c))
651
652#ifdef __GLIBC__
653 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
654 /* /usr/include/wctype.h incorrectly declares translations */
655 /* tables which provokes tons of compile-time warnings -- try */
656 /* to correct this */
657 #define wxCRT_TolowerW(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
658 #define wxCRT_ToupperW(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
659 #else /* !glibc 2.0 */
660 #define wxCRT_TolowerW towlower
661 #define wxCRT_ToupperW towupper
662 #endif
28efe654 663#else /* !__GLIBC__ */
410390cf
VS
664 /* There is a bug in VC6 C RTL: toxxx() functions dosn't do anything
665 with signed chars < 0, so "fix" it here. */
666 #define wxCRT_TolowerW(c) towlower((wxUChar)(wxChar)(c))
667 #define wxCRT_ToupperW(c) towupper((wxUChar)(wxChar)(c))
28efe654 668#endif /* __GLIBC__/!__GLIBC__ */
eb9524ca
VS
669
670
671
672
673
674/* -------------------------------------------------------------------------
675 wx wrappers for CRT functions in both char* and wchar_t* versions
676 ------------------------------------------------------------------------- */
677
678#ifdef __cplusplus
679
680/* NB: this belongs to wxcrt.h and not this header, but it makes life easier
681 * for buffer.h and stringimpl.h (both of which must be included before
682 * string.h, which is required by wxcrt.h) to have them here: */
683
684/* safe version of strlen() (returns 0 if passed NULL pointer) */
685inline size_t wxStrlen(const char *s) { return s ? wxCRT_StrlenA(s) : 0; }
686inline size_t wxStrlen(const wchar_t *s) { return s ? wxCRT_StrlenW(s) : 0; }
676a5687 687#ifndef wxWCHAR_T_IS_WXCHAR16
16882c9e 688 WXDLLIMPEXP_BASE size_t wxStrlen(const wxChar16 *s );
676a5687
RR
689#endif
690#ifndef wxWCHAR_T_IS_WXCHAR32
16882c9e 691 WXDLLIMPEXP_BASE size_t wxStrlen(const wxChar32 *s );
676a5687 692#endif
eb9524ca
VS
693#define wxWcslen wxCRT_StrlenW
694
695#define wxStrdupA wxCRT_StrdupA
696#define wxStrdupW wxCRT_StrdupW
697inline char* wxStrdup(const char *s) { return wxCRT_StrdupA(s); }
698inline wchar_t* wxStrdup(const wchar_t *s) { return wxCRT_StrdupW(s); }
676a5687 699#ifndef wxWCHAR_T_IS_WXCHAR16
16882c9e 700 WXDLLIMPEXP_BASE wxChar16* wxStrdup(const wxChar16* s);
676a5687
RR
701#endif
702#ifndef wxWCHAR_T_IS_WXCHAR32
16882c9e 703 WXDLLIMPEXP_BASE wxChar32* wxStrdup(const wxChar32* s);
676a5687 704#endif
eb9524ca
VS
705
706#endif /* __cplusplus */
707
708#endif /* _WX_WXCRTBASE_H_ */