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