3 * Purpose: Type-safe ANSI and Unicode builds compatible wrappers for
5 * Author: Joel Farley, Ove Kaaven
6 * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee
9 * Copyright: (c) 1998-2006 wxWidgets dev team
10 * Licence: wxWindows licence
13 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
15 #ifndef _WX_WXCRTBASE_H_
16 #define _WX_WXCRTBASE_H_
18 /* -------------------------------------------------------------------------
19 headers and missing declarations
20 ------------------------------------------------------------------------- */
22 #include "wx/chartype.h"
25 Standard headers we need here.
27 NB: don't include any wxWidgets headers here because almost all of them
30 NB2: User code should include wx/crt.h instead of including this
35 #if !defined(__WXPALMOS5__)
39 #if defined(__WXPALMOS__)
47 #if defined(__WINDOWS__) && !defined(__WXWINCE__)
51 #if defined(HAVE_STRTOK_R) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
52 char *strtok_r(char *, const char *, char **);
56 Using -std=c++{98,0x} option with mingw32 disables most of standard
57 library extensions, so we can't rely on the presence of common non-ANSI
58 functions, define a special symbol to test for this. Notice that this
59 doesn't need to be done for g++ under Linux where _GNU_SOURCE (which is
60 defined by default) still makes all common extensions available even in
63 #if defined(__MINGW32__) && defined(__STRICT_ANSI__)
64 #define __WX_STRICT_ANSI_GCC__
68 a few compilers don't have the (non standard but common) isascii function,
69 define it ourselves for them
72 #if defined(__MWERKS__) || defined(__WX_STRICT_ANSI_GCC__)
73 #define wxNEED_ISASCII
74 #elif defined(_WIN32_WCE)
76 #define wxNEED_ISASCII
82 inline int isascii(int c
) { return (unsigned)c
< 0x80; }
87 #define isspace(c) ((c) == wxT(' ') || (c) == wxT('\t'))
89 #endif /* _WIN32_WCE */
91 /* string.h functions */
93 #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)
95 #elif defined(__WXWINCE__)
103 WXDLLIMPEXP_BASE
char *strdup(const char* s
);
106 /* missing functions in some WinCE versions */
108 #if (_WIN32_WCE < 300)
109 WXDLLIMPEXP_BASE
void *calloc( size_t num
, size_t size
);
111 #endif /* _WIN32_WCE */
114 #if defined(__MWERKS__)
115 /* Metrowerks only has wide char support for OS X >= 10.3 */
116 #if !defined(__DARWIN__) || \
117 (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)
118 #define wxHAVE_MWERKS_UNICODE
121 #ifdef wxHAVE_MWERKS_UNICODE
122 #define HAVE_WPRINTF 1
123 #define HAVE_WCSRTOMBS 1
124 #define HAVE_VSWPRINTF 1
126 #endif /* __MWERKS__ */
129 /* -------------------------------------------------------------------------
130 UTF-8 locale handling
131 ------------------------------------------------------------------------- */
134 #if wxUSE_UNICODE_UTF8
135 /* flag indicating whether the current locale uses UTF-8 or not; must be
136 updated every time the locale is changed! */
137 #if wxUSE_UTF8_LOCALE_ONLY
138 #define wxLocaleIsUtf8 true
140 extern WXDLLIMPEXP_BASE
bool wxLocaleIsUtf8
;
142 /* function used to update the flag: */
143 extern WXDLLIMPEXP_BASE
void wxUpdateLocaleIsUtf8();
144 #else /* !wxUSE_UNICODE_UTF8 */
145 inline void wxUpdateLocaleIsUtf8() {}
146 #endif /* wxUSE_UNICODE_UTF8/!wxUSE_UNICODE_UTF8 */
147 #endif /* __cplusplus */
150 /* -------------------------------------------------------------------------
152 ------------------------------------------------------------------------- */
154 #define wxCRT_StrcatA strcat
155 #define wxCRT_StrchrA strchr
156 #define wxCRT_StrcmpA strcmp
157 #define wxCRT_StrcpyA strcpy
158 #define wxCRT_StrcspnA strcspn
159 #define wxCRT_StrlenA strlen
160 #define wxCRT_StrncatA strncat
161 #define wxCRT_StrncmpA strncmp
162 #define wxCRT_StrncpyA strncpy
163 #define wxCRT_StrpbrkA strpbrk
164 #define wxCRT_StrrchrA strrchr
165 #define wxCRT_StrspnA strspn
166 #define wxCRT_StrstrA strstr
168 #define wxCRT_StrcatW wcscat
169 #define wxCRT_StrchrW wcschr
170 #define wxCRT_StrcmpW wcscmp
171 #define wxCRT_StrcpyW wcscpy
172 #define wxCRT_StrcspnW wcscspn
173 #define wxCRT_StrncatW wcsncat
174 #define wxCRT_StrncmpW wcsncmp
175 #define wxCRT_StrncpyW wcsncpy
176 #define wxCRT_StrpbrkW wcspbrk
177 #define wxCRT_StrrchrW wcsrchr
178 #define wxCRT_StrspnW wcsspn
179 #define wxCRT_StrstrW wcsstr
181 /* these functions are not defined under CE, at least in VC8 CRT */
182 #if !defined(__WXWINCE__) && !defined(__WXPALMOS__)
183 #define wxCRT_StrcollA strcoll
184 #define wxCRT_StrxfrmA strxfrm
186 #define wxCRT_StrcollW wcscoll
187 #define wxCRT_StrxfrmW wcsxfrm
188 #endif /* __WXWINCE__ */
190 /* Almost all compiler have strdup(), but not quite all: CodeWarrior under
191 Mac and VC++ for Windows CE don't provide it; additionally, gcc under
192 Mac and OpenVMS do not have wcsdup: */
193 #if defined(__VISUALC__) && __VISUALC__ >= 1400
194 #define wxCRT_StrdupA _strdup
195 #elif !((defined(__MWERKS__) && defined(__WXMAC__)) || \
196 defined(__WXWINCE__) || \
197 defined(__WX_STRICT_ANSI_GCC__))
198 #define wxCRT_StrdupA strdup
201 // most Windows compilers provide _wcsdup()
202 #if defined(__WINDOWS__) && \
203 !(defined(__CYGWIN__) || defined(__WX_STRICT_ANSI_GCC__))
204 #define wxCRT_StrdupW _wcsdup
205 #elif defined(HAVE_WCSDUP)
206 #define wxCRT_StrdupW wcsdup
209 #ifdef wxHAVE_TCHAR_SUPPORT
210 /* we surely have wchar_t if we have TCHAR have wcslen() */
214 #endif /* wxHAVE_TCHAR_SUPPORT */
217 #define wxCRT_StrlenW wcslen
220 #define wxCRT_StrtodA strtod
221 #define wxCRT_StrtolA strtol
222 #define wxCRT_StrtoulA strtoul
223 #define wxCRT_StrtodW wcstod
224 #define wxCRT_StrtolW wcstol
225 #define wxCRT_StrtoulW wcstoul
228 #if __VISUALC__ >= 1300 && !defined(__WXWINCE__)
229 #define wxCRT_StrtollA _strtoi64
230 #define wxCRT_StrtoullA _strtoui64
231 #define wxCRT_StrtollW _wcstoi64
232 #define wxCRT_StrtoullW _wcstoui64
236 #define wxCRT_StrtollA strtoll
237 #define wxCRT_StrtoullA strtoull
238 #endif /* HAVE_STRTOULL */
240 /* assume that we have wcstoull(), which is also C99, too */
241 #define wxCRT_StrtollW wcstoll
242 #define wxCRT_StrtoullW wcstoull
243 #endif /* HAVE_WCSTOULL */
247 Only VC8 and later provide strnlen() and wcsnlen() functions under Windows
248 and it's also only available starting from Windows CE 6.0 only in CE build.
250 #if wxCHECK_VISUALC_VERSION(8) && (!defined(_WIN32_WCE) || (_WIN32_WCE >= 0x600))
260 #define wxCRT_StrnlenA strnlen
264 #define wxCRT_StrnlenW wcsnlen
267 /* define wxCRT_StricmpA/W and wxCRT_StrnicmpA/W for various compilers */
269 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
270 defined(__VISAGECPP__) || \
271 defined(__EMX__) || defined(__DJGPP__)
272 #define wxCRT_StricmpA stricmp
273 #define wxCRT_StrnicmpA strnicmp
274 #elif defined(__WXPALMOS__)
275 /* FIXME: There is no equivalent to strnicmp in the Palm OS API. This
276 * quick hack should do until one can be written.
278 #define wxCRT_StricmpA StrCaselessCompare
279 #define wxCRT_StrnicmpA StrNCaselessCompare
280 #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
281 (defined(__MWERKS__) && defined(__INTEL__))
282 #define wxCRT_StricmpA _stricmp
283 #define wxCRT_StrnicmpA _strnicmp
284 #elif defined(__UNIX__) || (defined(__GNUWIN32__) && !defined(__WX_STRICT_ANSI_GCC__))
285 #define wxCRT_StricmpA strcasecmp
286 #define wxCRT_StrnicmpA strncasecmp
287 /* #else -- use wxWidgets implementation */
291 #define wxCRT_StricmpW _wcsicmp
292 #define wxCRT_StrnicmpW _wcsnicmp
293 #elif defined(__UNIX__)
294 #ifdef HAVE_WCSCASECMP
295 #define wxCRT_StricmpW wcscasecmp
297 #ifdef HAVE_WCSNCASECMP
298 #define wxCRT_StrnicmpW wcsncasecmp
300 /* #else -- use wxWidgets implementation */
304 #define wxCRT_StrtokA(str, sep, last) strtok_r(str, sep, last)
306 /* FIXME-UTF8: detect and use wcstok() if available for wxCRT_StrtokW */
308 /* these are extern "C" because they are used by regex lib: */
313 #ifndef wxCRT_StrlenW
314 WXDLLIMPEXP_BASE
size_t wxCRT_StrlenW(const wchar_t *s
);
317 #ifndef wxCRT_StrncmpW
318 WXDLLIMPEXP_BASE
int wxCRT_StrncmpW(const wchar_t *s1
, const wchar_t *s2
, size_t n
);
325 /* FIXME-UTF8: remove this once we are Unicode only */
327 #define wxCRT_StrlenNative wxCRT_StrlenW
328 #define wxCRT_StrncmpNative wxCRT_StrncmpW
329 #define wxCRT_ToupperNative wxCRT_ToupperW
330 #define wxCRT_TolowerNative wxCRT_TolowerW
332 #define wxCRT_StrlenNative wxCRT_StrlenA
333 #define wxCRT_StrncmpNative wxCRT_StrncmpA
334 #define wxCRT_ToupperNative toupper
335 #define wxCRT_TolowerNative tolower
338 #ifndef wxCRT_StrcatW
339 WXDLLIMPEXP_BASE
wchar_t *wxCRT_StrcatW(wchar_t *dest
, const wchar_t *src
);
342 #ifndef wxCRT_StrchrW
343 WXDLLIMPEXP_BASE
const wchar_t *wxCRT_StrchrW(const wchar_t *s
, wchar_t c
);
346 #ifndef wxCRT_StrcmpW
347 WXDLLIMPEXP_BASE
int wxCRT_StrcmpW(const wchar_t *s1
, const wchar_t *s2
);
350 #ifndef wxCRT_StrcollW
351 WXDLLIMPEXP_BASE
int wxCRT_StrcollW(const wchar_t *s1
, const wchar_t *s2
);
354 #ifndef wxCRT_StrcpyW
355 WXDLLIMPEXP_BASE
wchar_t *wxCRT_StrcpyW(wchar_t *dest
, const wchar_t *src
);
358 #ifndef wxCRT_StrcspnW
359 WXDLLIMPEXP_BASE
size_t wxCRT_StrcspnW(const wchar_t *s
, const wchar_t *reject
);
362 #ifndef wxCRT_StrncatW
363 WXDLLIMPEXP_BASE
wchar_t *wxCRT_StrncatW(wchar_t *dest
, const wchar_t *src
, size_t n
);
366 #ifndef wxCRT_StrncpyW
367 WXDLLIMPEXP_BASE
wchar_t *wxCRT_StrncpyW(wchar_t *dest
, const wchar_t *src
, size_t n
);
370 #ifndef wxCRT_StrpbrkW
371 WXDLLIMPEXP_BASE
const wchar_t *wxCRT_StrpbrkW(const wchar_t *s
, const wchar_t *accept
);
374 #ifndef wxCRT_StrrchrW
375 WXDLLIMPEXP_BASE
const wchar_t *wxCRT_StrrchrW(const wchar_t *s
, wchar_t c
);
378 #ifndef wxCRT_StrspnW
379 WXDLLIMPEXP_BASE
size_t wxCRT_StrspnW(const wchar_t *s
, const wchar_t *accept
);
382 #ifndef wxCRT_StrstrW
383 WXDLLIMPEXP_BASE
const wchar_t *wxCRT_StrstrW(const wchar_t *haystack
, const wchar_t *needle
);
386 #ifndef wxCRT_StrtodW
387 WXDLLIMPEXP_BASE
double wxCRT_StrtodW(const wchar_t *nptr
, wchar_t **endptr
);
390 #ifndef wxCRT_StrtolW
391 WXDLLIMPEXP_BASE
long int wxCRT_StrtolW(const wchar_t *nptr
, wchar_t **endptr
, int base
);
394 #ifndef wxCRT_StrtoulW
395 WXDLLIMPEXP_BASE
unsigned long int wxCRT_StrtoulW(const wchar_t *nptr
, wchar_t **endptr
, int base
);
398 #ifndef wxCRT_StrxfrmW
399 WXDLLIMPEXP_BASE
size_t wxCRT_StrxfrmW(wchar_t *dest
, const wchar_t *src
, size_t n
);
402 #ifndef wxCRT_StrdupA
403 WXDLLIMPEXP_BASE
char *wxCRT_StrdupA(const char *psz
);
406 #ifndef wxCRT_StrdupW
407 WXDLLIMPEXP_BASE
wchar_t *wxCRT_StrdupW(const wchar_t *pwz
);
410 #ifndef wxCRT_StricmpA
411 WXDLLIMPEXP_BASE
int wxCRT_StricmpA(const char *psz1
, const char *psz2
);
414 #ifndef wxCRT_StricmpW
415 WXDLLIMPEXP_BASE
int wxCRT_StricmpW(const wchar_t *psz1
, const wchar_t *psz2
);
418 #ifndef wxCRT_StrnicmpA
419 WXDLLIMPEXP_BASE
int wxCRT_StrnicmpA(const char *psz1
, const char *psz2
, size_t len
);
422 #ifndef wxCRT_StrnicmpW
423 WXDLLIMPEXP_BASE
int wxCRT_StrnicmpW(const wchar_t *psz1
, const wchar_t *psz2
, size_t len
);
426 #ifndef wxCRT_StrtokA
427 WXDLLIMPEXP_BASE
char *wxCRT_StrtokA(char *psz
, const char *delim
, char **save_ptr
);
430 #ifndef wxCRT_StrtokW
431 WXDLLIMPEXP_BASE
wchar_t *wxCRT_StrtokW(wchar_t *psz
, const wchar_t *delim
, wchar_t **save_ptr
);
434 /* supply strtoll and strtoull, if needed */
436 #ifndef wxCRT_StrtollA
437 WXDLLIMPEXP_BASE wxLongLong_t
wxCRT_StrtollA(const char* nptr
,
440 WXDLLIMPEXP_BASE wxULongLong_t
wxCRT_StrtoullA(const char* nptr
,
444 #ifndef wxCRT_StrtollW
445 WXDLLIMPEXP_BASE wxLongLong_t
wxCRT_StrtollW(const wchar_t* nptr
,
448 WXDLLIMPEXP_BASE wxULongLong_t
wxCRT_StrtoullW(const wchar_t* nptr
,
452 #endif // wxLongLong_t
455 /* -------------------------------------------------------------------------
457 ------------------------------------------------------------------------- */
459 #if defined(__UNIX__) || defined(__WXMAC__) || defined(__WXPALMOS__)
466 /* these functions are only needed in the form used for filenames (i.e. char*
467 on Unix, wchar_t* on Windows), so we don't need to use A/W suffix: */
468 #if wxMBFILES || !wxUSE_UNICODE /* ANSI filenames */
470 #define wxCRT_Fopen fopen
471 #define wxCRT_Freopen freopen
472 #define wxCRT_Remove remove
473 #define wxCRT_Rename rename
475 #else /* Unicode filenames */
476 /* special case: these functions are missing under Win9x with Unicows so we
477 have to implement them ourselves */
478 #if wxUSE_UNICODE_MSLU || defined(__WX_STRICT_ANSI_GCC__)
479 WXDLLIMPEXP_BASE
FILE* wxMSLU__wfopen(const wchar_t *name
, const wchar_t *mode
);
480 WXDLLIMPEXP_BASE
FILE* wxMSLU__wfreopen(const wchar_t *name
, const wchar_t *mode
, FILE *stream
);
481 WXDLLIMPEXP_BASE
int wxMSLU__wrename(const wchar_t *oldname
, const wchar_t *newname
);
482 WXDLLIMPEXP_BASE
int wxMSLU__wremove(const wchar_t *name
);
483 #define wxCRT_Fopen wxMSLU__wfopen
484 #define wxCRT_Freopen wxMSLU__wfreopen
485 #define wxCRT_Remove wxMSLU__wremove
486 #define wxCRT_Rename wxMSLU__wrename
488 /* WinCE CRT doesn't provide these functions so use our own */
490 WXDLLIMPEXP_BASE
int wxCRT_Rename(const wchar_t *src
,
492 WXDLLIMPEXP_BASE
int wxCRT_Remove(const wchar_t *path
);
494 #define wxCRT_Rename _wrename
495 #define wxCRT_Remove _wremove
497 #define wxCRT_Fopen _wfopen
498 #define wxCRT_Freopen _wfreopen
501 #endif /* wxMBFILES/!wxMBFILES */
503 #define wxCRT_PutsA puts
504 #define wxCRT_FputsA fputs
505 #define wxCRT_FgetsA fgets
506 #define wxCRT_FputcA fputc
507 #define wxCRT_FgetcA fgetc
508 #define wxCRT_UngetcA ungetc
510 #ifdef wxHAVE_TCHAR_SUPPORT
511 #define wxCRT_PutsW _putws
512 #define wxCRT_FputsW fputws
513 #define wxCRT_FputcW fputwc
516 #define wxCRT_FputsW fputws
519 #define wxCRT_PutsW putws
522 #define wxCRT_FputcW fputwc
524 #define wxCRT_FgetsW fgetws
527 WXDLLIMPEXP_BASE
int wxCRT_PutsW(const wchar_t *ws
);
531 WXDLLIMPEXP_BASE
int wxCRT_FputsW(const wchar_t *ch
, FILE *stream
);
535 WXDLLIMPEXP_BASE
int wxCRT_FputcW(wchar_t wc
, FILE *stream
);
539 NB: tmpnam() is unsafe and thus is not wrapped!
540 Use other wxWidgets facilities instead:
541 wxFileName::CreateTempFileName, wxTempFile, or wxTempFileOutputStream
543 #define wxTmpnam(x) wxTmpnam_is_insecure_use_wxTempFile_instead
545 /* FIXME-CE: provide our own perror() using ::GetLastError() */
548 #define wxCRT_PerrorA perror
549 #ifdef wxHAVE_TCHAR_SUPPORT
550 #define wxCRT_PerrorW _wperror
553 #endif /* !__WXWINCE__ */
555 /* -------------------------------------------------------------------------
557 ------------------------------------------------------------------------- */
559 /* there are no env vars at all under CE, so no _tgetenv neither */
561 /* can't define as inline function as this is a C file... */
562 #define wxCRT_GetenvA(name) (name, NULL)
563 #define wxCRT_GetenvW(name) (name, NULL)
565 #define wxCRT_GetenvA getenv
567 #define wxCRT_GetenvW _wgetenv
571 #ifndef wxCRT_GetenvW
572 WXDLLIMPEXP_BASE
wchar_t * wxCRT_GetenvW(const wchar_t *name
);
576 #define wxCRT_SystemA system
577 /* mingw32 doesn't provide _tsystem() or _wsystem(): */
578 #if defined(_tsystem)
579 #define wxCRT_SystemW _wsystem
582 #define wxCRT_AtofA atof
583 #define wxCRT_AtoiA atoi
584 #define wxCRT_AtolA atol
586 #if defined(__MWERKS__)
588 #define wxCRT_AtofW watof
589 #define wxCRT_AtoiW watoi
590 #define wxCRT_AtolW watol
591 /* else: use ANSI versions */
593 #elif defined(wxHAVE_TCHAR_SUPPORT) && !defined(__WX_STRICT_ANSI_GCC__)
594 #define wxCRT_AtoiW _wtoi
595 #define wxCRT_AtolW _wtol
596 /* _wtof doesn't exist */
599 #define wxCRT_AtofW(s) wcstod(s, NULL)
601 #define wxCRT_AtolW(s) wcstol(s, NULL, 10)
602 /* wcstoi doesn't exist */
606 There are 2 unrelated problems with these functions under Mac:
607 a) Metrowerks MSL CRT implements them strictly in C99 sense and
608 doesn't support (very common) extension of allowing to call
609 mbstowcs(NULL, ...) which makes it pretty useless as you can't
610 know the size of the needed buffer
611 b) OS X <= 10.2 declares and even defined these functions but
612 doesn't really implement them -- they always return an error
614 So use our own replacements in both cases.
616 #if defined(__MWERKS__) && defined(__MSL__)
617 #define wxNEED_WX_MBSTOWCS
619 #if defined(__WXPALMOS__)
620 #define wxNEED_WX_MBSTOWCS
624 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2
625 #define wxNEED_WX_MBSTOWCS
629 #ifdef wxNEED_WX_MBSTOWCS
630 /* even though they are defined and "implemented", they are bad and just
631 stubs so we need our own - we need these even in ANSI builds!! */
632 WXDLLIMPEXP_BASE
size_t wxMbstowcs(wchar_t *, const char *, size_t);
633 WXDLLIMPEXP_BASE
size_t wxWcstombs(char *, const wchar_t *, size_t);
635 #define wxMbstowcs mbstowcs
636 #define wxWcstombs wcstombs
641 /* -------------------------------------------------------------------------
643 ------------------------------------------------------------------------- */
645 #define wxCRT_StrftimeA strftime
648 IRIX provides not one but two versions of wcsftime(): XPG4 one which
649 uses "const char*" for the third parameter and so can't be used and the
650 correct, XPG5, one. Unfortunately we can't just define _XOPEN_SOURCE
651 high enough to get XPG5 version as this undefines other symbols which
652 make other functions we use unavailable (see <standards.h> for gory
653 details). So just declare the XPG5 version ourselves, we're extremely
654 unlikely to ever be compiled on a system without it. But if we ever do,
655 a configure test would need to be added for it (and _MIPS_SYMBOL_PRESENT
656 should be used to check for its presence during run-time, i.e. it would
657 probably be simpler to just always use our own wxCRT_StrftimeW() below
658 if it does ever become a problem).
664 _xpg5_wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm
* );
665 #define wxCRT_StrftimeW _xpg5_wcsftime
668 // assume it's always available, this does seem to be the case for now
669 #define wxCRT_StrftimeW wcsftime
670 #endif /* ! __WXPALMOS__ */
673 #ifndef wxCRT_StrftimeW
674 WXDLLIMPEXP_BASE
size_t wxCRT_StrftimeW(wchar_t *s
, size_t max
,
676 const struct tm
*tm
);
681 /* -------------------------------------------------------------------------
683 ------------------------------------------------------------------------- */
686 #define WXWCHAR_T_CAST(c) (wint_t)(c)
688 #define WXWCHAR_T_CAST(c) c
691 #define wxCRT_IsalnumW(c) iswalnum(WXWCHAR_T_CAST(c))
692 #define wxCRT_IsalphaW(c) iswalpha(WXWCHAR_T_CAST(c))
693 #define wxCRT_IscntrlW(c) iswcntrl(WXWCHAR_T_CAST(c))
694 #define wxCRT_IsdigitW(c) iswdigit(WXWCHAR_T_CAST(c))
695 #define wxCRT_IsgraphW(c) iswgraph(WXWCHAR_T_CAST(c))
696 #define wxCRT_IslowerW(c) iswlower(WXWCHAR_T_CAST(c))
697 #define wxCRT_IsprintW(c) iswprint(WXWCHAR_T_CAST(c))
698 #define wxCRT_IspunctW(c) iswpunct(WXWCHAR_T_CAST(c))
699 #define wxCRT_IsspaceW(c) iswspace(WXWCHAR_T_CAST(c))
700 #define wxCRT_IsupperW(c) iswupper(WXWCHAR_T_CAST(c))
701 #define wxCRT_IsxdigitW(c) iswxdigit(WXWCHAR_T_CAST(c))
704 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
705 /* /usr/include/wctype.h incorrectly declares translations */
706 /* tables which provokes tons of compile-time warnings -- try */
707 /* to correct this */
708 #define wxCRT_TolowerW(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
709 #define wxCRT_ToupperW(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
710 #else /* !glibc 2.0 */
711 #define wxCRT_TolowerW towlower
712 #define wxCRT_ToupperW towupper
714 #else /* !__GLIBC__ */
715 /* There is a bug in VC6 C RTL: toxxx() functions dosn't do anything
716 with signed chars < 0, so "fix" it here. */
717 #define wxCRT_TolowerW(c) towlower((wxUChar)(wxChar)(c))
718 #define wxCRT_ToupperW(c) towupper((wxUChar)(wxChar)(c))
719 #endif /* __GLIBC__/!__GLIBC__ */
725 /* -------------------------------------------------------------------------
726 wx wrappers for CRT functions in both char* and wchar_t* versions
727 ------------------------------------------------------------------------- */
731 /* NB: this belongs to wxcrt.h and not this header, but it makes life easier
732 * for buffer.h and stringimpl.h (both of which must be included before
733 * string.h, which is required by wxcrt.h) to have them here: */
735 /* safe version of strlen() (returns 0 if passed NULL pointer) */
736 inline size_t wxStrlen(const char *s
) { return s
? wxCRT_StrlenA(s
) : 0; }
737 inline size_t wxStrlen(const wchar_t *s
) { return s
? wxCRT_StrlenW(s
) : 0; }
738 #ifndef wxWCHAR_T_IS_WXCHAR16
739 WXDLLIMPEXP_BASE
size_t wxStrlen(const wxChar16
*s
);
741 #ifndef wxWCHAR_T_IS_WXCHAR32
742 WXDLLIMPEXP_BASE
size_t wxStrlen(const wxChar32
*s
);
744 #define wxWcslen wxCRT_StrlenW
746 #define wxStrdupA wxCRT_StrdupA
747 #define wxStrdupW wxCRT_StrdupW
748 inline char* wxStrdup(const char *s
) { return wxCRT_StrdupA(s
); }
749 inline wchar_t* wxStrdup(const wchar_t *s
) { return wxCRT_StrdupW(s
); }
750 #ifndef wxWCHAR_T_IS_WXCHAR16
751 WXDLLIMPEXP_BASE wxChar16
* wxStrdup(const wxChar16
* s
);
753 #ifndef wxWCHAR_T_IS_WXCHAR32
754 WXDLLIMPEXP_BASE wxChar32
* wxStrdup(const wxChar32
* s
);
757 #endif /* __cplusplus */
759 #endif /* _WX_WXCRTBASE_H_ */