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
41 #if defined(__WINDOWS__) && !defined(__WXWINCE__)
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 **);
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
57 #if defined(__MINGW32__) && defined(__STRICT_ANSI__)
58 #define __WX_STRICT_ANSI_GCC__
62 a few compilers don't have the (non standard but common) isascii function,
63 define it ourselves for them
66 #if defined(__MWERKS__) || defined(__WX_STRICT_ANSI_GCC__)
67 #define wxNEED_ISASCII
68 #elif defined(_WIN32_WCE)
70 #define wxNEED_ISASCII
76 inline int isascii(int c
) { return (unsigned)c
< 0x80; }
81 #define isspace(c) ((c) == wxT(' ') || (c) == wxT('\t'))
83 #endif /* _WIN32_WCE */
85 /* string.h functions */
87 #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)
89 #elif defined(__WXWINCE__)
97 WXDLLIMPEXP_BASE
char *strdup(const char* s
);
100 /* missing functions in some WinCE versions */
102 #if (_WIN32_WCE < 300)
103 WXDLLIMPEXP_BASE
void *calloc( size_t num
, size_t size
);
105 #endif /* _WIN32_WCE */
108 #if defined(__MWERKS__)
109 /* Metrowerks only has wide char support for OS X >= 10.3 */
110 #if !defined(__DARWIN__) || \
111 (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)
112 #define wxHAVE_MWERKS_UNICODE
115 #ifdef wxHAVE_MWERKS_UNICODE
116 #define HAVE_WPRINTF 1
117 #define HAVE_WCSRTOMBS 1
118 #define HAVE_VSWPRINTF 1
120 #endif /* __MWERKS__ */
123 /* -------------------------------------------------------------------------
124 UTF-8 locale handling
125 ------------------------------------------------------------------------- */
128 #if wxUSE_UNICODE_UTF8
129 /* flag indicating whether the current locale uses UTF-8 or not; must be
130 updated every time the locale is changed! */
131 #if wxUSE_UTF8_LOCALE_ONLY
132 #define wxLocaleIsUtf8 true
134 extern WXDLLIMPEXP_BASE
bool wxLocaleIsUtf8
;
136 /* function used to update the flag: */
137 extern WXDLLIMPEXP_BASE
void wxUpdateLocaleIsUtf8();
138 #else /* !wxUSE_UNICODE_UTF8 */
139 inline void wxUpdateLocaleIsUtf8() {}
140 #endif /* wxUSE_UNICODE_UTF8/!wxUSE_UNICODE_UTF8 */
141 #endif /* __cplusplus */
144 /* -------------------------------------------------------------------------
146 ------------------------------------------------------------------------- */
148 #define wxCRT_StrcatA strcat
149 #define wxCRT_StrchrA strchr
150 #define wxCRT_StrcmpA strcmp
151 #define wxCRT_StrcpyA strcpy
152 #define wxCRT_StrcspnA strcspn
153 #define wxCRT_StrlenA strlen
154 #define wxCRT_StrncatA strncat
155 #define wxCRT_StrncmpA strncmp
156 #define wxCRT_StrncpyA strncpy
157 #define wxCRT_StrpbrkA strpbrk
158 #define wxCRT_StrrchrA strrchr
159 #define wxCRT_StrspnA strspn
160 #define wxCRT_StrstrA strstr
162 #define wxCRT_StrcatW wcscat
163 #define wxCRT_StrchrW wcschr
164 #define wxCRT_StrcmpW wcscmp
165 #define wxCRT_StrcpyW wcscpy
166 #define wxCRT_StrcspnW wcscspn
167 #define wxCRT_StrncatW wcsncat
168 #define wxCRT_StrncmpW wcsncmp
169 #define wxCRT_StrncpyW wcsncpy
170 #define wxCRT_StrpbrkW wcspbrk
171 #define wxCRT_StrrchrW wcsrchr
172 #define wxCRT_StrspnW wcsspn
173 #define wxCRT_StrstrW wcsstr
175 /* these functions are not defined under CE, at least in VC8 CRT */
176 #if !defined(__WXWINCE__)
177 #define wxCRT_StrcollA strcoll
178 #define wxCRT_StrxfrmA strxfrm
180 #define wxCRT_StrcollW wcscoll
181 #define wxCRT_StrxfrmW wcsxfrm
182 #endif /* __WXWINCE__ */
184 /* Almost all compiler have strdup(), but not quite all: CodeWarrior under
185 Mac and VC++ for Windows CE don't provide it. Another special case is gcc in
186 strict ANSI mode: normally it doesn't provide strdup() but MinGW does
187 provide it under MSVC-compatible name so test for it before checking
188 __WX_STRICT_ANSI_GCC__. */
189 #if (defined(__VISUALC__) && __VISUALC__ >= 1400) || \
191 #define wxCRT_StrdupA _strdup
192 #elif !((defined(__MWERKS__) && defined(__WXMAC__)) || \
193 defined(__WXWINCE__) || \
194 defined(__WX_STRICT_ANSI_GCC__))
195 #define wxCRT_StrdupA strdup
198 /* most Windows compilers provide _wcsdup() */
199 #if defined(__WINDOWS__) && \
200 !(defined(__CYGWIN__) || defined(__WX_STRICT_ANSI_GCC__))
201 #define wxCRT_StrdupW _wcsdup
202 #elif defined(HAVE_WCSDUP)
203 #define wxCRT_StrdupW wcsdup
206 #ifdef wxHAVE_TCHAR_SUPPORT
207 /* we surely have wchar_t if we have TCHAR have wcslen() */
211 #endif /* wxHAVE_TCHAR_SUPPORT */
214 #define wxCRT_StrlenW wcslen
217 #define wxCRT_StrtodA strtod
218 #define wxCRT_StrtolA strtol
219 #define wxCRT_StrtoulA strtoul
220 #define wxCRT_StrtodW wcstod
221 #define wxCRT_StrtolW wcstol
222 #define wxCRT_StrtoulW wcstoul
225 #if __VISUALC__ >= 1300 && !defined(__WXWINCE__)
226 #define wxCRT_StrtollA _strtoi64
227 #define wxCRT_StrtoullA _strtoui64
228 #define wxCRT_StrtollW _wcstoi64
229 #define wxCRT_StrtoullW _wcstoui64
233 #define wxCRT_StrtollA strtoll
234 #define wxCRT_StrtoullA strtoull
235 #endif /* HAVE_STRTOULL */
237 /* assume that we have wcstoull(), which is also C99, too */
238 #define wxCRT_StrtollW wcstoll
239 #define wxCRT_StrtoullW wcstoull
240 #endif /* HAVE_WCSTOULL */
244 Only VC8 and later provide strnlen() and wcsnlen() functions under Windows
245 and it's also only available starting from Windows CE 6.0 only in CE build.
247 #if wxCHECK_VISUALC_VERSION(8) && (!defined(_WIN32_WCE) || (_WIN32_WCE >= 0x600))
257 #define wxCRT_StrnlenA strnlen
261 #define wxCRT_StrnlenW wcsnlen
264 /* define wxCRT_StricmpA/W and wxCRT_StrnicmpA/W for various compilers */
266 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
267 defined(__VISAGECPP__) || \
268 defined(__EMX__) || defined(__DJGPP__)
269 #define wxCRT_StricmpA stricmp
270 #define wxCRT_StrnicmpA strnicmp
271 #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
272 (defined(__MWERKS__) && defined(__INTEL__))
273 #define wxCRT_StricmpA _stricmp
274 #define wxCRT_StrnicmpA _strnicmp
275 #elif defined(__UNIX__) || (defined(__GNUWIN32__) && !defined(__WX_STRICT_ANSI_GCC__))
276 #define wxCRT_StricmpA strcasecmp
277 #define wxCRT_StrnicmpA strncasecmp
278 /* #else -- use wxWidgets implementation */
282 #define wxCRT_StricmpW _wcsicmp
283 #define wxCRT_StrnicmpW _wcsnicmp
284 #elif defined(__UNIX__)
285 #ifdef HAVE_WCSCASECMP
286 #define wxCRT_StricmpW wcscasecmp
288 #ifdef HAVE_WCSNCASECMP
289 #define wxCRT_StrnicmpW wcsncasecmp
291 /* #else -- use wxWidgets implementation */
295 #define wxCRT_StrtokA(str, sep, last) strtok_r(str, sep, last)
297 /* FIXME-UTF8: detect and use wcstok() if available for wxCRT_StrtokW */
299 /* these are extern "C" because they are used by regex lib: */
304 #ifndef wxCRT_StrlenW
305 WXDLLIMPEXP_BASE
size_t wxCRT_StrlenW(const wchar_t *s
);
308 #ifndef wxCRT_StrncmpW
309 WXDLLIMPEXP_BASE
int wxCRT_StrncmpW(const wchar_t *s1
, const wchar_t *s2
, size_t n
);
316 /* FIXME-UTF8: remove this once we are Unicode only */
318 #define wxCRT_StrlenNative wxCRT_StrlenW
319 #define wxCRT_StrncmpNative wxCRT_StrncmpW
320 #define wxCRT_ToupperNative wxCRT_ToupperW
321 #define wxCRT_TolowerNative wxCRT_TolowerW
323 #define wxCRT_StrlenNative wxCRT_StrlenA
324 #define wxCRT_StrncmpNative wxCRT_StrncmpA
325 #define wxCRT_ToupperNative toupper
326 #define wxCRT_TolowerNative tolower
329 #ifndef wxCRT_StrcatW
330 WXDLLIMPEXP_BASE
wchar_t *wxCRT_StrcatW(wchar_t *dest
, const wchar_t *src
);
333 #ifndef wxCRT_StrchrW
334 WXDLLIMPEXP_BASE
const wchar_t *wxCRT_StrchrW(const wchar_t *s
, wchar_t c
);
337 #ifndef wxCRT_StrcmpW
338 WXDLLIMPEXP_BASE
int wxCRT_StrcmpW(const wchar_t *s1
, const wchar_t *s2
);
341 #ifndef wxCRT_StrcollW
342 WXDLLIMPEXP_BASE
int wxCRT_StrcollW(const wchar_t *s1
, const wchar_t *s2
);
345 #ifndef wxCRT_StrcpyW
346 WXDLLIMPEXP_BASE
wchar_t *wxCRT_StrcpyW(wchar_t *dest
, const wchar_t *src
);
349 #ifndef wxCRT_StrcspnW
350 WXDLLIMPEXP_BASE
size_t wxCRT_StrcspnW(const wchar_t *s
, const wchar_t *reject
);
353 #ifndef wxCRT_StrncatW
354 WXDLLIMPEXP_BASE
wchar_t *wxCRT_StrncatW(wchar_t *dest
, const wchar_t *src
, size_t n
);
357 #ifndef wxCRT_StrncpyW
358 WXDLLIMPEXP_BASE
wchar_t *wxCRT_StrncpyW(wchar_t *dest
, const wchar_t *src
, size_t n
);
361 #ifndef wxCRT_StrpbrkW
362 WXDLLIMPEXP_BASE
const wchar_t *wxCRT_StrpbrkW(const wchar_t *s
, const wchar_t *accept
);
365 #ifndef wxCRT_StrrchrW
366 WXDLLIMPEXP_BASE
const wchar_t *wxCRT_StrrchrW(const wchar_t *s
, wchar_t c
);
369 #ifndef wxCRT_StrspnW
370 WXDLLIMPEXP_BASE
size_t wxCRT_StrspnW(const wchar_t *s
, const wchar_t *accept
);
373 #ifndef wxCRT_StrstrW
374 WXDLLIMPEXP_BASE
const wchar_t *wxCRT_StrstrW(const wchar_t *haystack
, const wchar_t *needle
);
377 #ifndef wxCRT_StrtodW
378 WXDLLIMPEXP_BASE
double wxCRT_StrtodW(const wchar_t *nptr
, wchar_t **endptr
);
381 #ifndef wxCRT_StrtolW
382 WXDLLIMPEXP_BASE
long int wxCRT_StrtolW(const wchar_t *nptr
, wchar_t **endptr
, int base
);
385 #ifndef wxCRT_StrtoulW
386 WXDLLIMPEXP_BASE
unsigned long int wxCRT_StrtoulW(const wchar_t *nptr
, wchar_t **endptr
, int base
);
389 #ifndef wxCRT_StrxfrmW
390 WXDLLIMPEXP_BASE
size_t wxCRT_StrxfrmW(wchar_t *dest
, const wchar_t *src
, size_t n
);
393 #ifndef wxCRT_StrdupA
394 WXDLLIMPEXP_BASE
char *wxCRT_StrdupA(const char *psz
);
397 #ifndef wxCRT_StrdupW
398 WXDLLIMPEXP_BASE
wchar_t *wxCRT_StrdupW(const wchar_t *pwz
);
401 #ifndef wxCRT_StricmpA
402 WXDLLIMPEXP_BASE
int wxCRT_StricmpA(const char *psz1
, const char *psz2
);
405 #ifndef wxCRT_StricmpW
406 WXDLLIMPEXP_BASE
int wxCRT_StricmpW(const wchar_t *psz1
, const wchar_t *psz2
);
409 #ifndef wxCRT_StrnicmpA
410 WXDLLIMPEXP_BASE
int wxCRT_StrnicmpA(const char *psz1
, const char *psz2
, size_t len
);
413 #ifndef wxCRT_StrnicmpW
414 WXDLLIMPEXP_BASE
int wxCRT_StrnicmpW(const wchar_t *psz1
, const wchar_t *psz2
, size_t len
);
417 #ifndef wxCRT_StrtokA
418 WXDLLIMPEXP_BASE
char *wxCRT_StrtokA(char *psz
, const char *delim
, char **save_ptr
);
421 #ifndef wxCRT_StrtokW
422 WXDLLIMPEXP_BASE
wchar_t *wxCRT_StrtokW(wchar_t *psz
, const wchar_t *delim
, wchar_t **save_ptr
);
425 /* supply strtoll and strtoull, if needed */
427 #ifndef wxCRT_StrtollA
428 WXDLLIMPEXP_BASE wxLongLong_t
wxCRT_StrtollA(const char* nptr
,
431 WXDLLIMPEXP_BASE wxULongLong_t
wxCRT_StrtoullA(const char* nptr
,
435 #ifndef wxCRT_StrtollW
436 WXDLLIMPEXP_BASE wxLongLong_t
wxCRT_StrtollW(const wchar_t* nptr
,
439 WXDLLIMPEXP_BASE wxULongLong_t
wxCRT_StrtoullW(const wchar_t* nptr
,
443 #endif /* wxLongLong_t */
446 /* -------------------------------------------------------------------------
448 ------------------------------------------------------------------------- */
450 #if defined(__UNIX__) || defined(__WXMAC__)
457 /* these functions are only needed in the form used for filenames (i.e. char*
458 on Unix, wchar_t* on Windows), so we don't need to use A/W suffix: */
459 #if wxMBFILES || !wxUSE_UNICODE /* ANSI filenames */
461 #define wxCRT_Fopen fopen
462 #define wxCRT_Freopen freopen
463 #define wxCRT_Remove remove
464 #define wxCRT_Rename rename
466 #else /* Unicode filenames */
467 /* special case: these functions are missing under Win9x with Unicows so we
468 have to implement them ourselves */
469 #if wxUSE_UNICODE_MSLU || defined(__WX_STRICT_ANSI_GCC__)
470 WXDLLIMPEXP_BASE
FILE* wxMSLU__wfopen(const wchar_t *name
, const wchar_t *mode
);
471 WXDLLIMPEXP_BASE
FILE* wxMSLU__wfreopen(const wchar_t *name
, const wchar_t *mode
, FILE *stream
);
472 WXDLLIMPEXP_BASE
int wxMSLU__wrename(const wchar_t *oldname
, const wchar_t *newname
);
473 WXDLLIMPEXP_BASE
int wxMSLU__wremove(const wchar_t *name
);
474 #define wxCRT_Fopen wxMSLU__wfopen
475 #define wxCRT_Freopen wxMSLU__wfreopen
476 #define wxCRT_Remove wxMSLU__wremove
477 #define wxCRT_Rename wxMSLU__wrename
479 /* WinCE CRT doesn't provide these functions so use our own */
481 WXDLLIMPEXP_BASE
int wxCRT_Rename(const wchar_t *src
,
483 WXDLLIMPEXP_BASE
int wxCRT_Remove(const wchar_t *path
);
485 #define wxCRT_Rename _wrename
486 #define wxCRT_Remove _wremove
488 #define wxCRT_Fopen _wfopen
489 #define wxCRT_Freopen _wfreopen
492 #endif /* wxMBFILES/!wxMBFILES */
494 #define wxCRT_PutsA puts
495 #define wxCRT_FputsA fputs
496 #define wxCRT_FgetsA fgets
497 #define wxCRT_FputcA fputc
498 #define wxCRT_FgetcA fgetc
499 #define wxCRT_UngetcA ungetc
501 #ifdef wxHAVE_TCHAR_SUPPORT
502 #define wxCRT_PutsW _putws
503 #define wxCRT_FputsW fputws
504 #define wxCRT_FputcW fputwc
507 #define wxCRT_FputsW fputws
510 #define wxCRT_PutsW putws
513 #define wxCRT_FputcW fputwc
515 #define wxCRT_FgetsW fgetws
518 WXDLLIMPEXP_BASE
int wxCRT_PutsW(const wchar_t *ws
);
522 WXDLLIMPEXP_BASE
int wxCRT_FputsW(const wchar_t *ch
, FILE *stream
);
526 WXDLLIMPEXP_BASE
int wxCRT_FputcW(wchar_t wc
, FILE *stream
);
530 NB: tmpnam() is unsafe and thus is not wrapped!
531 Use other wxWidgets facilities instead:
532 wxFileName::CreateTempFileName, wxTempFile, or wxTempFileOutputStream
534 #define wxTmpnam(x) wxTmpnam_is_insecure_use_wxTempFile_instead
536 /* FIXME-CE: provide our own perror() using ::GetLastError() */
539 #define wxCRT_PerrorA perror
540 #ifdef wxHAVE_TCHAR_SUPPORT
541 #define wxCRT_PerrorW _wperror
544 #endif /* !__WXWINCE__ */
546 /* -------------------------------------------------------------------------
548 ------------------------------------------------------------------------- */
550 /* there are no env vars at all under CE, so no _tgetenv neither */
552 /* can't define as inline function as this is a C file... */
553 #define wxCRT_GetenvA(name) (name, NULL)
554 #define wxCRT_GetenvW(name) (name, NULL)
556 #define wxCRT_GetenvA getenv
558 #define wxCRT_GetenvW _wgetenv
562 #ifndef wxCRT_GetenvW
563 WXDLLIMPEXP_BASE
wchar_t * wxCRT_GetenvW(const wchar_t *name
);
567 #define wxCRT_SystemA system
568 /* mingw32 doesn't provide _tsystem() or _wsystem(): */
569 #if defined(_tsystem)
570 #define wxCRT_SystemW _wsystem
573 #define wxCRT_AtofA atof
574 #define wxCRT_AtoiA atoi
575 #define wxCRT_AtolA atol
577 #if defined(__MWERKS__)
579 #define wxCRT_AtofW watof
580 #define wxCRT_AtoiW watoi
581 #define wxCRT_AtolW watol
582 /* else: use ANSI versions */
584 #elif defined(wxHAVE_TCHAR_SUPPORT) && !defined(__WX_STRICT_ANSI_GCC__)
585 #define wxCRT_AtoiW _wtoi
586 #define wxCRT_AtolW _wtol
587 /* _wtof doesn't exist */
590 #define wxCRT_AtofW(s) wcstod(s, NULL)
592 #define wxCRT_AtolW(s) wcstol(s, NULL, 10)
593 /* wcstoi doesn't exist */
597 There are 2 unrelated problems with these functions under Mac:
598 a) Metrowerks MSL CRT implements them strictly in C99 sense and
599 doesn't support (very common) extension of allowing to call
600 mbstowcs(NULL, ...) which makes it pretty useless as you can't
601 know the size of the needed buffer
602 b) OS X <= 10.2 declares and even defined these functions but
603 doesn't really implement them -- they always return an error
605 So use our own replacements in both cases.
607 #if defined(__MWERKS__) && defined(__MSL__)
608 #define wxNEED_WX_MBSTOWCS
612 #if !defined(__WXOSX_IPHONE__) && MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2
613 #define wxNEED_WX_MBSTOWCS
617 #ifdef wxNEED_WX_MBSTOWCS
618 /* even though they are defined and "implemented", they are bad and just
619 stubs so we need our own - we need these even in ANSI builds!! */
620 WXDLLIMPEXP_BASE
size_t wxMbstowcs(wchar_t *, const char *, size_t);
621 WXDLLIMPEXP_BASE
size_t wxWcstombs(char *, const wchar_t *, size_t);
623 #define wxMbstowcs mbstowcs
624 #define wxWcstombs wcstombs
629 /* -------------------------------------------------------------------------
631 ------------------------------------------------------------------------- */
633 #define wxCRT_StrftimeA strftime
636 IRIX provides not one but two versions of wcsftime(): XPG4 one which
637 uses "const char*" for the third parameter and so can't be used and the
638 correct, XPG5, one. Unfortunately we can't just define _XOPEN_SOURCE
639 high enough to get XPG5 version as this undefines other symbols which
640 make other functions we use unavailable (see <standards.h> for gory
641 details). So just declare the XPG5 version ourselves, we're extremely
642 unlikely to ever be compiled on a system without it. But if we ever do,
643 a configure test would need to be added for it (and _MIPS_SYMBOL_PRESENT
644 should be used to check for its presence during run-time, i.e. it would
645 probably be simpler to just always use our own wxCRT_StrftimeW() below
646 if it does ever become a problem).
652 _xpg5_wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm
* );
653 #define wxCRT_StrftimeW _xpg5_wcsftime
656 Assume it's always available under non-Unix systems as this does seem
657 to be the case for now. And under Unix we trust configure to detect it
658 (except for SGI special case above).
660 #if defined(HAVE_WCSFTIME) || !defined(__UNIX__)
661 #define wxCRT_StrftimeW wcsftime
665 #ifndef wxCRT_StrftimeW
666 WXDLLIMPEXP_BASE
size_t wxCRT_StrftimeW(wchar_t *s
, size_t max
,
668 const struct tm
*tm
);
673 /* -------------------------------------------------------------------------
675 ------------------------------------------------------------------------- */
678 #define WXWCHAR_T_CAST(c) (wint_t)(c)
680 #define WXWCHAR_T_CAST(c) c
683 #define wxCRT_IsalnumW(c) iswalnum(WXWCHAR_T_CAST(c))
684 #define wxCRT_IsalphaW(c) iswalpha(WXWCHAR_T_CAST(c))
685 #define wxCRT_IscntrlW(c) iswcntrl(WXWCHAR_T_CAST(c))
686 #define wxCRT_IsdigitW(c) iswdigit(WXWCHAR_T_CAST(c))
687 #define wxCRT_IsgraphW(c) iswgraph(WXWCHAR_T_CAST(c))
688 #define wxCRT_IslowerW(c) iswlower(WXWCHAR_T_CAST(c))
689 #define wxCRT_IsprintW(c) iswprint(WXWCHAR_T_CAST(c))
690 #define wxCRT_IspunctW(c) iswpunct(WXWCHAR_T_CAST(c))
691 #define wxCRT_IsspaceW(c) iswspace(WXWCHAR_T_CAST(c))
692 #define wxCRT_IsupperW(c) iswupper(WXWCHAR_T_CAST(c))
693 #define wxCRT_IsxdigitW(c) iswxdigit(WXWCHAR_T_CAST(c))
696 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
697 /* /usr/include/wctype.h incorrectly declares translations */
698 /* tables which provokes tons of compile-time warnings -- try */
699 /* to correct this */
700 #define wxCRT_TolowerW(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
701 #define wxCRT_ToupperW(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
702 #else /* !glibc 2.0 */
703 #define wxCRT_TolowerW towlower
704 #define wxCRT_ToupperW towupper
706 #else /* !__GLIBC__ */
707 /* There is a bug in VC6 C RTL: toxxx() functions dosn't do anything
708 with signed chars < 0, so "fix" it here. */
709 #define wxCRT_TolowerW(c) towlower((wxUChar)(wxChar)(c))
710 #define wxCRT_ToupperW(c) towupper((wxUChar)(wxChar)(c))
711 #endif /* __GLIBC__/!__GLIBC__ */
717 /* -------------------------------------------------------------------------
718 wx wrappers for CRT functions in both char* and wchar_t* versions
719 ------------------------------------------------------------------------- */
723 /* NB: this belongs to wxcrt.h and not this header, but it makes life easier
724 * for buffer.h and stringimpl.h (both of which must be included before
725 * string.h, which is required by wxcrt.h) to have them here: */
727 /* safe version of strlen() (returns 0 if passed NULL pointer) */
728 inline size_t wxStrlen(const char *s
) { return s
? wxCRT_StrlenA(s
) : 0; }
729 inline size_t wxStrlen(const wchar_t *s
) { return s
? wxCRT_StrlenW(s
) : 0; }
730 #ifndef wxWCHAR_T_IS_WXCHAR16
731 WXDLLIMPEXP_BASE
size_t wxStrlen(const wxChar16
*s
);
733 #ifndef wxWCHAR_T_IS_WXCHAR32
734 WXDLLIMPEXP_BASE
size_t wxStrlen(const wxChar32
*s
);
736 #define wxWcslen wxCRT_StrlenW
738 #define wxStrdupA wxCRT_StrdupA
739 #define wxStrdupW wxCRT_StrdupW
740 inline char* wxStrdup(const char *s
) { return wxCRT_StrdupA(s
); }
741 inline wchar_t* wxStrdup(const wchar_t *s
) { return wxCRT_StrdupW(s
); }
742 #ifndef wxWCHAR_T_IS_WXCHAR16
743 WXDLLIMPEXP_BASE wxChar16
* wxStrdup(const wxChar16
* s
);
745 #ifndef wxWCHAR_T_IS_WXCHAR32
746 WXDLLIMPEXP_BASE wxChar32
* wxStrdup(const wxChar32
* s
);
749 #endif /* __cplusplus */
751 #endif /* _WX_WXCRTBASE_H_ */