]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxcrtbase.h
ATTRIBUTE_PRINTF doesn't work with wchar_t* format strings in gcc
[wxWidgets.git] / include / wx / wxcrtbase.h
1 /*
2 * Name: wx/wxcrtbase.h
3 * Purpose: Type-safe ANSI and Unicode builds compatible wrappers for
4 * CRT functions
5 * Author: Joel Farley, Ove Kåven
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!
29 */
30
31 #include <stdio.h>
32 #include <string.h>
33 #include <ctype.h>
34 #include <wctype.h>
35 #include <time.h>
36
37
38 #if defined(HAVE_STRTOK_R) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
39 char *strtok_r(char *, const char *, char **);
40 #endif
41
42 /*
43 a few compilers don't have the (non standard but common) isascii function,
44 define it ourselves for them
45 */
46 #ifndef isascii
47 #if defined(__MWERKS__)
48 #define wxNEED_ISASCII
49 #elif defined(_WIN32_WCE)
50 #if _WIN32_WCE <= 211
51 #define wxNEED_ISASCII
52 #endif
53 #endif
54 #endif /* isascii */
55
56 #ifdef wxNEED_ISASCII
57 inline int isascii(int c) { return (unsigned)c < 0x80; }
58 #endif
59
60 #ifdef _WIN32_WCE
61 #if _WIN32_WCE <= 211
62 #define isspace(c) ((c) == _T(' ') || (c) == _T('\t'))
63 #endif
64 #endif /* _WIN32_WCE */
65
66 /* string.h functions */
67 #ifndef strdup
68 #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)
69 #define wxNEED_STRDUP
70 #elif defined(__WXWINCE__)
71 #if _WIN32_WCE <= 211
72 #define wxNEED_STRDUP
73 #endif
74 #endif
75 #endif /* strdup */
76
77 #ifdef wxNEED_STRDUP
78 WXDLLIMPEXP_BASE char *strdup(const char* s);
79 #endif
80
81 /* missing functions in some WinCE versions */
82 #ifdef _WIN32_WCE
83 #if (_WIN32_WCE < 300)
84 WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size );
85 #endif
86 #endif /* _WIN32_WCE */
87
88
89 #if defined(__MWERKS__)
90 /* Metrowerks only has wide char support for OS X >= 10.3 */
91 #if !defined(__DARWIN__) || \
92 (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)
93 #define wxHAVE_MWERKS_UNICODE
94 #endif
95
96 #ifdef wxHAVE_MWERKS_UNICODE
97 #define HAVE_WPRINTF 1
98 #define HAVE_WCSRTOMBS 1
99 #define HAVE_VSWPRINTF 1
100 #endif
101 #endif /* __MWERKS__ */
102
103
104 /* -------------------------------------------------------------------------
105 UTF-8 locale handling
106 ------------------------------------------------------------------------- */
107
108 #ifdef __cplusplus
109 #if wxUSE_UNICODE_UTF8
110 // flag indicating whether the current locale uses UTF-8 or not; must be
111 // updated every time the locale is changed!
112 #if wxUSE_UTF8_LOCALE_ONLY
113 #define wxLocaleIsUtf8 true
114 #else
115 extern WXDLLIMPEXP_BASE bool wxLocaleIsUtf8;
116 #endif
117 // function used to update the flag:
118 extern WXDLLIMPEXP_BASE void wxUpdateLocaleIsUtf8();
119 #else // !wxUSE_UNICODE_UTF8
120 inline void wxUpdateLocaleIsUtf8() {}
121 #endif // wxUSE_UNICODE_UTF8/!wxUSE_UNICODE_UTF8
122 #endif // __cplusplus
123
124
125 /* -------------------------------------------------------------------------
126 string.h
127 ------------------------------------------------------------------------- */
128
129 #define wxCRT_StrcatA strcat
130 #define wxCRT_StrchrA strchr
131 #define wxCRT_StrcmpA strcmp
132 #define wxCRT_StrcollA strcoll
133 #define wxCRT_StrcpyA strcpy
134 #define wxCRT_StrcspnA strcspn
135 #define wxCRT_StrlenA strlen
136 #define wxCRT_StrncatA strncat
137 #define wxCRT_StrncmpA strncmp
138 #define wxCRT_StrncpyA strncpy
139 #define wxCRT_StrpbrkA strpbrk
140 #define wxCRT_StrrchrA strrchr
141 #define wxCRT_StrspnA strspn
142 #define wxCRT_StrstrA strstr
143 #define wxCRT_StrxfrmA strxfrm
144
145 /*
146 The system C library on Mac OS X 10.2 and below does not support unicode: in
147 other words all wide-character functions such as towupper et al. do simply
148 not exist so we need to provide our own in that context, except for the
149 wchar_t definition/typedef itself.
150
151 We need to do this for both project builder and CodeWarrior as the latter
152 uses the system C library in Mach builds for wide character support, which
153 as mentioned does not exist on 10.2 and below.
154 */
155 #if defined(__DARWIN__) && (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_2)
156 #define wxHAS_NO_WCS_FUNCTIONS
157 #endif
158
159 #ifndef wxHAS_NO_WCS_FUNCTIONS
160 #define wxCRT_StrcatW wcscat
161 #define wxCRT_StrchrW wcschr
162 #define wxCRT_StrcmpW wcscmp
163 #define wxCRT_StrcollW wcscoll
164 #define wxCRT_StrcpyW wcscpy
165 #define wxCRT_StrcspnW wcscspn
166 #define wxCRT_StrncatW wcsncat
167 #define wxCRT_StrncmpW wcsncmp
168 #define wxCRT_StrncpyW wcsncpy
169 #define wxCRT_StrpbrkW wcspbrk
170 #define wxCRT_StrrchrW wcsrchr
171 #define wxCRT_StrspnW wcsspn
172 #define wxCRT_StrstrW wcsstr
173 #define wxCRT_StrxfrmW wcsxfrm
174
175 /* Almost all compiler have strdup(), but not quite all: CodeWarrior under
176 Mac and VC++ for Windows CE don't provide it */
177 #if defined(__VISUALC__) && __VISUALC__ >= 1400
178 #define wxCRT_StrdupA _strdup
179 #elif !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
180 #define wxCRT_StrdupA strdup
181 #endif
182 #ifdef __WINDOWS__
183 #define wxCRT_StrdupW _wcsdup
184 #else
185 #define wxCRT_StrdupW wcsdup
186 #endif
187 #else
188 #define wxCRT_StrdupA strdup
189 /* the rest is implemented in our code */
190 #endif
191
192 #ifdef wxHAVE_TCHAR_SUPPORT
193 /* we surely have wchar_t if we have TCHAR have wcslen() */
194 #ifndef HAVE_WCSLEN
195 #define HAVE_WCSLEN
196 #endif
197 #endif /* wxHAVE_TCHAR_SUPPORT */
198
199 #ifdef HAVE_WCSLEN
200 #define wxCRT_StrlenW wcslen
201 #endif
202
203 #define wxCRT_StrtodA strtod
204 #define wxCRT_StrtolA strtol
205 #define wxCRT_StrtoulA strtoul
206 #define wxCRT_StrtodW wcstod
207 #define wxCRT_StrtolW wcstol
208 #define wxCRT_StrtoulW wcstoul
209
210 #ifdef __VISUALC__
211 #if __VISUALC__ >= 1300 && !defined(__WXWINCE__)
212 #define wxCRT_StrtollA _strtoi64
213 #define wxCRT_StrtoullA _strtoui64
214 #define wxCRT_StrtollW _wcstoi64
215 #define wxCRT_StrtoullW _wcstoui64
216 #endif /* VC++ 7+ */
217 #else
218 #ifdef HAVE_STRTOULL
219 #define wxCRT_StrtollA strtoll
220 #define wxCRT_StrtoullA strtoull
221 #endif /* HAVE_STRTOULL */
222 #ifdef HAVE_WCSTOULL
223 /* assume that we have wcstoull(), which is also C99, too */
224 #define wxCRT_StrtollW wcstoll
225 #define wxCRT_StrtoullW wcstoull
226 #endif /* HAVE_WCSTOULL */
227 #endif
228
229
230 /* define wxCRT_StricmpA/W and wxCRT_StrnicmpA/W for various compilers */
231
232 /* note that we definitely are going to need our own version for widechar
233 * versions */
234 #if !defined(wxCRT_StricmpA)
235 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
236 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
237 defined(__EMX__) || defined(__DJGPP__)
238 #define wxCRT_StricmpA stricmp
239 #define wxCRT_StrnicmpA strnicmp
240 #elif defined(__WXPALMOS__)
241 /* FIXME: There is no equivalent to strnicmp in the Palm OS API. This
242 * quick hack should do until one can be written.
243 */
244 #define wxCRT_StricmpA StrCaselessCompare
245 #define wxCRT_StrnicmpA strnicmp
246 #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
247 (defined(__MWERKS__) && defined(__INTEL__))
248 #define wxCRT_StricmpA _stricmp
249 #define wxCRT_StrnicmpA _strnicmp
250 #elif defined(__UNIX__) || defined(__GNUWIN32__)
251 #define wxCRT_StricmpA strcasecmp
252 #define wxCRT_StrnicmpA strncasecmp
253 /* #else -- use wxWidgets implementation */
254 #endif
255 #endif /* !defined(wxCRT_StricmpA) */
256 /* FIXME-UTF8: use wcs(n)casecmp if available for *W versions */
257
258 #ifdef HAVE_STRTOK_R
259 #define wxCRT_StrtokA(str, sep, last) strtok_r(str, sep, last)
260 #endif
261 /* FIXME-UTF8: detect and use wcstok() if available for wxCRT_StrtokW */
262
263 /* these are extern "C" because they are used by regex lib: */
264 #ifdef __cplusplus
265 extern "C" {
266 #endif
267
268 #ifndef wxCRT_StrlenW
269 WXDLLIMPEXP_BASE size_t wxCRT_StrlenW(const wchar_t *s);
270 #endif
271
272 #ifndef wxCRT_StrncmpW
273 WXDLLIMPEXP_BASE int wxCRT_StrncmpW(const wchar_t *s1, const wchar_t *s2, size_t n);
274 #endif
275
276 #ifdef __cplusplus
277 }
278 #endif
279
280 /* FIXME-UTF8: remove this once we are Unicode only */
281 #if wxUSE_UNICODE
282 #define wxCRT_StrlenNative wxCRT_StrlenW
283 #define wxCRT_StrncmpNative wxCRT_StrncmpW
284 #define wxCRT_ToupperNative wxCRT_ToupperW
285 #define wxCRT_TolowerNative wxCRT_TolowerW
286 #else
287 #define wxCRT_StrlenNative wxCRT_StrlenA
288 #define wxCRT_StrncmpNative wxCRT_StrncmpA
289 #define wxCRT_ToupperNative toupper
290 #define wxCRT_TolowerNative tolower
291 #endif
292
293 #ifndef wxCRT_StrcatW
294 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrcatW(wchar_t *dest, const wchar_t *src);
295 #endif
296
297 #ifndef wxCRT_StrchrW
298 WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrchrW(const wchar_t *s, wchar_t c);
299 #endif
300
301 #ifndef wxCRT_StrcmpW
302 WXDLLIMPEXP_BASE int wxCRT_StrcmpW(const wchar_t *s1, const wchar_t *s2);
303 #endif
304
305 #ifndef wxCRT_StrcollW
306 WXDLLIMPEXP_BASE int wxCRT_StrcollW(const wchar_t *s1, const wchar_t *s2);
307 #endif
308
309 #ifndef wxCRT_StrcpyW
310 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrcpyW(wchar_t *dest, const wchar_t *src);
311 #endif
312
313 #ifndef wxCRT_StrcspnW
314 WXDLLIMPEXP_BASE size_t wxCRT_StrcspnW(const wchar_t *s, const wchar_t *reject);
315 #endif
316
317 #ifndef wxCRT_StrncatW
318 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrncatW(wchar_t *dest, const wchar_t *src, size_t n);
319 #endif
320
321 #ifndef wxCRT_StrncpyW
322 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrncpyW(wchar_t *dest, const wchar_t *src, size_t n);
323 #endif
324
325 #ifndef wxCRT_StrpbrkW
326 WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrpbrkW(const wchar_t *s, const wchar_t *accept);
327 #endif
328
329 #ifndef wxCRT_StrrchrW
330 WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrrchrW(const wchar_t *s, wchar_t c);
331 #endif
332
333 #ifndef wxCRT_StrspnW
334 WXDLLIMPEXP_BASE size_t wxCRT_StrspnW(const wchar_t *s, const wchar_t *accept);
335 #endif
336
337 #ifndef wxCRT_StrstrW
338 WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrstrW(const wchar_t *haystack, const wchar_t *needle);
339 #endif
340
341 #ifndef wxCRT_StrtodW
342 WXDLLIMPEXP_BASE double wxCRT_StrtodW(const wchar_t *nptr, wchar_t **endptr);
343 #endif
344
345 #ifndef wxCRT_StrtolW
346 WXDLLIMPEXP_BASE long int wxCRT_StrtolW(const wchar_t *nptr, wchar_t **endptr, int base);
347 #endif
348
349 #ifndef wxCRT_StrtoulW
350 WXDLLIMPEXP_BASE unsigned long int wxCRT_StrtoulW(const wchar_t *nptr, wchar_t **endptr, int base);
351 #endif
352
353 #ifndef wxCRT_StrxfrmW
354 WXDLLIMPEXP_BASE size_t wxCRT_StrxfrmW(wchar_t *dest, const wchar_t *src, size_t n);
355 #endif
356
357 #ifndef wxCRT_StrdupA
358 WXDLLIMPEXP_BASE char *wxCRT_StrdupA(const char *psz);
359 #endif
360
361 #ifndef wxCRT_StrdupW
362 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrdupW(const wchar_t *pwz);
363 #endif
364
365 #ifndef wxCRT_StricmpA
366 WXDLLIMPEXP_BASE int wxCRT_StricmpA(const char *psz1, const char *psz2);
367 #endif
368
369 #ifndef wxCRT_StricmpW
370 WXDLLIMPEXP_BASE int wxCRT_StricmpW(const wchar_t *psz1, const wchar_t *psz2);
371 #endif
372
373 #ifndef wxCRT_StrnicmpA
374 WXDLLIMPEXP_BASE int wxCRT_StrnicmpA(const char *psz1, const char *psz2, size_t len);
375 #endif
376
377 #ifndef wxCRT_StrnicmpW
378 WXDLLIMPEXP_BASE int wxCRT_StrnicmpW(const wchar_t *psz1, const wchar_t *psz2, size_t len);
379 #endif
380
381 #ifndef wxCRT_StrtokA
382 WXDLLIMPEXP_BASE char *wxCRT_StrtokA(char *psz, const char *delim, char **save_ptr);
383 #endif
384
385 #ifndef wxCRT_StrtokW
386 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrtokW(wchar_t *psz, const wchar_t *delim, wchar_t **save_ptr);
387 #endif
388
389 /* supply strtoll and strtoull, if needed */
390 #ifndef wxCRT_StrtollA
391 WXDLLIMPEXP_BASE wxLongLong_t wxCRT_StrtollA(const char* nptr, char** endptr, int base);
392 WXDLLIMPEXP_BASE wxULongLong_t wxCRT_StrtoullA(const char* nptr, char** endptr, int base);
393 #endif
394 #ifndef wxCRT_StrtollW
395 WXDLLIMPEXP_BASE wxLongLong_t wxCRT_StrtollW(const wchar_t* nptr, wchar_t** endptr, int base);
396 WXDLLIMPEXP_BASE wxULongLong_t wxCRT_StrtoullW(const wchar_t* nptr, wchar_t** endptr, int base);
397 #endif
398
399
400 /* -------------------------------------------------------------------------
401 stdio.h
402 ------------------------------------------------------------------------- */
403
404 #if defined(__UNIX__) || defined(__WXMAC__)
405 #define wxMBFILES 1
406 #else
407 #define wxMBFILES 0
408 #endif
409
410
411 /* these functions are only needed in the form used for filenames (i.e. char*
412 on Unix, wchar_t* on Windows), so we don't need to use A/W suffix: */
413 #if wxMBFILES || !wxUSE_UNICODE // ANSI filenames
414
415 #define wxCRT_Fopen fopen
416 #define wxCRT_Freopen freopen
417 #define wxCRT_Remove remove
418 #define wxCRT_Rename rename
419
420 #else // Unicode filenames
421
422 /* special case: these functions are missing under Win9x with Unicows so we
423 have to implement them ourselves */
424 #if wxUSE_UNICODE_MSLU
425 WXDLLIMPEXP_BASE FILE* wxMSLU__wfopen(const wchar_t *name, const wchar_t *mode);
426 WXDLLIMPEXP_BASE FILE* wxMSLU__wfreopen(const wchar_t *name, const wchar_t *mode, FILE *stream);
427 WXDLLIMPEXP_BASE int wxMSLU__wrename(const wchar_t *oldname, const wchar_t *newname);
428 WXDLLIMPEXP_BASE int wxMSLU__wremove(const wchar_t *name);
429 #define wxCRT_Fopen wxMSLU__wfopen
430 #define wxCRT_Remove wxMSLU__wremove
431 #define wxCRT_Rename wxMSLU__wrename
432 #else
433 #define wxCRT_Rename _wrename
434 #define wxCRT_Fopen _wfopen
435 #define wxCRT_Freopen _wfreopen
436 #ifdef __WXWINCE__
437 /* carefully: wxCRT_Remove() must return 0 on success while
438 DeleteFile() returns 0 on error, so don't just define one as
439 the other */
440 int wxCRT_Remove(const wchar_t *path);
441 #else
442 #define wxCRT_Remove _wremove
443 #endif
444 #endif
445
446 #endif // wxMBFILES/!wxMBFILES
447
448 #define wxCRT_PutsA puts
449 #define wxCRT_FputsA fputs
450 #define wxCRT_FgetsA fgets
451 #define wxCRT_FputcA fputc
452 #define wxCRT_FgetcA fgetc
453 #define wxCRT_UngetcA ungetc
454
455 #ifndef wxHAS_NO_WCS_FUNCTIONS
456 #ifdef wxHAVE_TCHAR_SUPPORT
457 #define wxCRT_PutsW _putws
458 #define wxCRT_FputsW fputws
459 #define wxCRT_FputcW fputwc
460 #endif
461 #ifdef HAVE_FPUTWS
462 #define wxCRT_FputsW fputws
463 #endif
464 #ifdef HAVE_PUTWS
465 #define wxCRT_PutsW putws
466 #endif
467 #ifdef HAVE_FPUTWC
468 #define wxCRT_FputcW fputwc
469 #endif
470 #define wxCRT_FgetsW fgetws
471 #endif // !wxHAS_NO_WCS_FUNCTIONS
472
473 #ifndef wxCRT_PutsW
474 WXDLLIMPEXP_BASE int wxCRT_PutsW(const wchar_t *ws);
475 #endif
476
477 #ifndef wxCRT_FputsW
478 WXDLLIMPEXP_BASE int wxCRT_FputsW(const wchar_t *ch, FILE *stream);
479 #endif
480
481 #ifndef wxCRT_FputcW
482 WXDLLIMPEXP_BASE int wxCRT_FputcW(wchar_t wc, FILE *stream);
483 #endif
484
485 #define wxCRT_TmpnamA tmpnam
486 #ifdef _ttmpnam
487 #define wxCRT_TmpnamW _wtmpnam
488 #endif
489
490 #ifndef wxCRT_TmpnamW
491 WXDLLIMPEXP_BASE wchar_t *wxCRT_TmpnamW(wchar_t *s);
492 #endif
493
494 #define wxCRT_PerrorA perror
495 #ifdef wxHAVE_TCHAR_SUPPORT
496 #define wxCRT_PerrorW _wperror
497 #endif
498
499 /* -------------------------------------------------------------------------
500 stdlib.h
501 ------------------------------------------------------------------------- */
502
503 /* there are no env vars at all under CE, so no _tgetenv neither */
504 #ifdef __WXWINCE__
505 /* can't define as inline function as this is a C file... */
506 #define wxCRT_GetenvA(name) ((char*)NULL)
507 #define wxCRT_GetenvW(name) ((wchar_t*)NULL)
508 #else
509 #define wxCRT_GetenvA getenv
510 #ifdef _tgetenv
511 #define wxCRT_GetenvW _wgetenv
512 #endif
513 #endif
514
515 #ifndef wxCRT_GetenvW
516 WXDLLIMPEXP_BASE wchar_t * wxCRT_GetenvW(const wchar_t *name);
517 #endif
518
519
520 #define wxCRT_SystemA system
521 /* mingw32 doesn't provide _tsystem() or _wsystem(): */
522 #if defined(_tsystem)
523 #define wxCRT_SystemW _wsystem
524 #endif
525
526 #define wxCRT_AtofA atof
527 #define wxCRT_AtoiA atoi
528 #define wxCRT_AtolA atol
529
530 #if defined(__MWERKS__)
531 #if defined(__MSL__)
532 #define wxCRT_AtofW watof
533 #define wxCRT_AtoiW watoi
534 #define wxCRT_AtolW watol
535 /* else: use ANSI versions */
536 #endif
537 #elif defined(wxHAVE_TCHAR_SUPPORT)
538 #define wxCRT_AtoiW _wtoi
539 #define wxCRT_AtolW _wtol
540 /* _wtof doesn't exist */
541 #else
542 #define wxCRT_AtofW(s) wcstof(s, NULL)
543 #define wxCRT_AtolW(s) wcstol(s, NULL, 10)
544 /* wcstoi doesn't exist */
545 #endif
546
547 /*
548 There are 2 unrelated problems with these functions under Mac:
549 a) Metrowerks MSL CRT implements them strictly in C99 sense and
550 doesn't support (very common) extension of allowing to call
551 mbstowcs(NULL, ...) which makes it pretty useless as you can't
552 know the size of the needed buffer
553 b) OS X <= 10.2 declares and even defined these functions but
554 doesn't really implement them -- they always return an error
555
556 So use our own replacements in both cases.
557 */
558 #if defined(__MWERKS__) && defined(__MSL__)
559 #define wxNEED_WX_MBSTOWCS
560 #endif
561
562 #ifdef __DARWIN__
563 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2
564 #define wxNEED_WX_MBSTOWCS
565 #endif
566 #endif
567
568 #ifdef wxNEED_WX_MBSTOWCS
569 /* even though they are defined and "implemented", they are bad and just
570 stubs so we need our own - we need these even in ANSI builds!! */
571 WXDLLIMPEXP_BASE size_t wxMbstowcs(wchar_t *, const char *, size_t);
572 WXDLLIMPEXP_BASE size_t wxWcstombs(char *, const wchar_t *, size_t);
573 #else
574 #define wxMbstowcs mbstowcs
575 #define wxWcstombs wcstombs
576 #endif
577
578
579
580 /* -------------------------------------------------------------------------
581 time.h
582 ------------------------------------------------------------------------- */
583
584 #define wxCRT_StrftimeA strftime
585 /* FIXME-UTF8: when is this available? */
586 #define wxCRT_StrftimeW wcsftime
587
588 #ifndef wxCRT_StrftimeW
589 WXDLLIMPEXP_BASE size_t wxCRT_StrftimeW(wchar_t *s, size_t max,
590 const wchar_t *fmt,
591 const struct tm *tm);
592 #endif
593
594
595
596 /* -------------------------------------------------------------------------
597 ctype.h
598 ------------------------------------------------------------------------- */
599
600 #ifdef wxHAS_NO_WCS_FUNCTIONS
601 #define wxNEED_WX_CTYPE_H
602 #endif
603
604 #ifdef __WATCOMC__
605 #define WXWCHAR_T_CAST(c) (wint_t)(c)
606 #else
607 #define WXWCHAR_T_CAST(c) c
608 #endif
609
610 #ifdef wxNEED_WX_CTYPE_H
611
612 /* RN: Used only under OSX <= 10.2 currently */
613 WXDLLIMPEXP_BASE int wxCRT_IsalnumW(wchar_t ch);
614 WXDLLIMPEXP_BASE int wxCRT_IsalphaW(wchar_t ch);
615 WXDLLIMPEXP_BASE int wxCRT_IscntrlW(wchar_t ch);
616 WXDLLIMPEXP_BASE int wxCRT_IsdigitW(wchar_t ch);
617 WXDLLIMPEXP_BASE int wxCRT_IsgraphW(wchar_t ch);
618 WXDLLIMPEXP_BASE int wxCRT_IslowerW(wchar_t ch);
619 WXDLLIMPEXP_BASE int wxCRT_IsprintW(wchar_t ch);
620 WXDLLIMPEXP_BASE int wxCRT_IspunctW(wchar_t ch);
621 WXDLLIMPEXP_BASE int wxCRT_IsspaceW(wchar_t ch);
622 WXDLLIMPEXP_BASE int wxCRT_IsupperW(wchar_t ch);
623 WXDLLIMPEXP_BASE int wxCRT_IsxdigitW(wchar_t ch);
624 /* extern "C" because needed by regex code */
625 WXDLLIMPEXP_BASE extern "C" int wxCRT_TolowerW(wchar_t ch);
626 WXDLLIMPEXP_BASE extern "C" int wxCRT_ToupperW(wchar_t ch);
627
628 #else // !defined(wxNEED_WX_CTYPE_H)
629
630 #define wxCRT_IsalnumW(c) iswalnum(WXWCHAR_T_CAST(c))
631 #define wxCRT_IsalphaW(c) iswalpha(WXWCHAR_T_CAST(c))
632 #define wxCRT_IscntrlW(c) iswcntrl(WXWCHAR_T_CAST(c))
633 #define wxCRT_IsdigitW(c) iswdigit(WXWCHAR_T_CAST(c))
634 #define wxCRT_IsgraphW(c) iswgraph(WXWCHAR_T_CAST(c))
635 #define wxCRT_IslowerW(c) iswlower(WXWCHAR_T_CAST(c))
636 #define wxCRT_IsprintW(c) iswprint(WXWCHAR_T_CAST(c))
637 #define wxCRT_IspunctW(c) iswpunct(WXWCHAR_T_CAST(c))
638 #define wxCRT_IsspaceW(c) iswspace(WXWCHAR_T_CAST(c))
639 #define wxCRT_IsupperW(c) iswupper(WXWCHAR_T_CAST(c))
640 #define wxCRT_IsxdigitW(c) iswxdigit(WXWCHAR_T_CAST(c))
641
642 #ifdef __GLIBC__
643 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
644 /* /usr/include/wctype.h incorrectly declares translations */
645 /* tables which provokes tons of compile-time warnings -- try */
646 /* to correct this */
647 #define wxCRT_TolowerW(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
648 #define wxCRT_ToupperW(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
649 #else /* !glibc 2.0 */
650 #define wxCRT_TolowerW towlower
651 #define wxCRT_ToupperW towupper
652 #endif
653 #else // !__GLIBC__
654 /* There is a bug in VC6 C RTL: toxxx() functions dosn't do anything
655 with signed chars < 0, so "fix" it here. */
656 #define wxCRT_TolowerW(c) towlower((wxUChar)(wxChar)(c))
657 #define wxCRT_ToupperW(c) towupper((wxUChar)(wxChar)(c))
658 #endif // __GLIBC__/!__GLIBC__
659 #endif // !defined(wxNEED_WX_CTYPE_H)
660
661
662
663
664
665 /* -------------------------------------------------------------------------
666 wx wrappers for CRT functions in both char* and wchar_t* versions
667 ------------------------------------------------------------------------- */
668
669 #ifdef __cplusplus
670
671 /* NB: this belongs to wxcrt.h and not this header, but it makes life easier
672 * for buffer.h and stringimpl.h (both of which must be included before
673 * string.h, which is required by wxcrt.h) to have them here: */
674
675 /* safe version of strlen() (returns 0 if passed NULL pointer) */
676 inline size_t wxStrlen(const char *s) { return s ? wxCRT_StrlenA(s) : 0; }
677 inline size_t wxStrlen(const wchar_t *s) { return s ? wxCRT_StrlenW(s) : 0; }
678 #define wxWcslen wxCRT_StrlenW
679
680 #define wxStrdupA wxCRT_StrdupA
681 #define wxStrdupW wxCRT_StrdupW
682 inline char* wxStrdup(const char *s) { return wxCRT_StrdupA(s); }
683 inline wchar_t* wxStrdup(const wchar_t *s) { return wxCRT_StrdupW(s); }
684
685 #endif /* __cplusplus */
686
687 #endif /* _WX_WXCRTBASE_H_ */