]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxcrtbase.h
Add wxActivateEvent::GetActivationReason().
[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 Kaaven
6 * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee
7 * Created: 1998/06/12
8 * Copyright: (c) 1998-2006 wxWidgets dev team
9 * Licence: wxWindows licence
10 */
11
12 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
13
14 #ifndef _WX_WXCRTBASE_H_
15 #define _WX_WXCRTBASE_H_
16
17 /* -------------------------------------------------------------------------
18 headers and missing declarations
19 ------------------------------------------------------------------------- */
20
21 #include "wx/chartype.h"
22
23 /*
24 Standard headers we need here.
25
26 NB: don't include any wxWidgets headers here because almost all of them
27 include this one!
28
29 NB2: User code should include wx/crt.h instead of including this
30 header directly.
31
32 */
33
34 #include <stdio.h>
35 #include <string.h>
36 #include <ctype.h>
37 #include <wctype.h>
38 #include <time.h>
39
40 #if defined(__WINDOWS__) && !defined(__WXWINCE__)
41 #include <io.h>
42 #endif
43
44 #if defined(HAVE_STRTOK_R) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
45 char *strtok_r(char *, const char *, char **);
46 #endif
47
48 /*
49 Using -std=c++{98,0x} option with mingw32 disables most of standard
50 library extensions, so we can't rely on the presence of common non-ANSI
51 functions, define a special symbol to test for this. Notice that this
52 doesn't need to be done for g++ under Linux where _GNU_SOURCE (which is
53 defined by default) still makes all common extensions available even in
54 ANSI mode.
55 */
56 #if defined(__MINGW32__) && defined(__STRICT_ANSI__)
57 #define __WX_STRICT_ANSI_GCC__
58 #endif
59
60 /*
61 a few compilers don't have the (non standard but common) isascii function,
62 define it ourselves for them
63 */
64 #ifndef isascii
65 #if defined(__WX_STRICT_ANSI_GCC__)
66 #define wxNEED_ISASCII
67 #elif defined(_WIN32_WCE)
68 #if _WIN32_WCE <= 211
69 #define wxNEED_ISASCII
70 #endif
71 #endif
72 #endif /* isascii */
73
74 #ifdef wxNEED_ISASCII
75 inline int isascii(int c) { return (unsigned)c < 0x80; }
76 #endif
77
78 #ifdef _WIN32_WCE
79 #if _WIN32_WCE <= 211
80 #define isspace(c) ((c) == wxT(' ') || (c) == wxT('\t'))
81 #endif
82 #endif /* _WIN32_WCE */
83
84 /* string.h functions */
85 #ifndef strdup
86 #if defined(__WXWINCE__)
87 #if _WIN32_WCE <= 211
88 #define wxNEED_STRDUP
89 #endif
90 #endif
91 #endif /* strdup */
92
93 #ifdef wxNEED_STRDUP
94 WXDLLIMPEXP_BASE char *strdup(const char* s);
95 #endif
96
97 /* missing functions in some WinCE versions */
98 #ifdef _WIN32_WCE
99 #if (_WIN32_WCE < 300)
100 WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size );
101 #endif
102 #endif /* _WIN32_WCE */
103
104
105 /* -------------------------------------------------------------------------
106 UTF-8 locale handling
107 ------------------------------------------------------------------------- */
108
109 #ifdef __cplusplus
110 #if wxUSE_UNICODE_UTF8
111 /* flag indicating whether the current locale uses UTF-8 or not; must be
112 updated every time the locale is changed! */
113 #if wxUSE_UTF8_LOCALE_ONLY
114 #define wxLocaleIsUtf8 true
115 #else
116 extern WXDLLIMPEXP_BASE bool wxLocaleIsUtf8;
117 #endif
118 /* function used to update the flag: */
119 extern WXDLLIMPEXP_BASE void wxUpdateLocaleIsUtf8();
120 #else /* !wxUSE_UNICODE_UTF8 */
121 inline void wxUpdateLocaleIsUtf8() {}
122 #endif /* wxUSE_UNICODE_UTF8/!wxUSE_UNICODE_UTF8 */
123 #endif /* __cplusplus */
124
125
126 /* -------------------------------------------------------------------------
127 string.h
128 ------------------------------------------------------------------------- */
129
130 #define wxCRT_StrcatA strcat
131 #define wxCRT_StrchrA strchr
132 #define wxCRT_StrcmpA strcmp
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
144 #define wxCRT_StrcatW wcscat
145 #define wxCRT_StrchrW wcschr
146 #define wxCRT_StrcmpW wcscmp
147 #define wxCRT_StrcpyW wcscpy
148 #define wxCRT_StrcspnW wcscspn
149 #define wxCRT_StrncatW wcsncat
150 #define wxCRT_StrncmpW wcsncmp
151 #define wxCRT_StrncpyW wcsncpy
152 #define wxCRT_StrpbrkW wcspbrk
153 #define wxCRT_StrrchrW wcsrchr
154 #define wxCRT_StrspnW wcsspn
155 #define wxCRT_StrstrW wcsstr
156
157 /* these functions are not defined under CE, at least in VC8 CRT */
158 #if !defined(__WXWINCE__)
159 #define wxCRT_StrcollA strcoll
160 #define wxCRT_StrxfrmA strxfrm
161
162 #define wxCRT_StrcollW wcscoll
163 #define wxCRT_StrxfrmW wcsxfrm
164 #endif /* __WXWINCE__ */
165
166 /* Almost all compilers have strdup(), but VC++ and MinGW call it _strdup().
167 And it's not available in MinGW strict ANSI mode nor under Windows CE. */
168 #if (defined(__VISUALC__) && __VISUALC__ >= 1400) || (defined(_MSC_VER) && _MSC_VER >= 1400 && defined (__INTELC__))
169 #define wxCRT_StrdupA _strdup
170 #elif defined(__MINGW32__)
171 #ifndef __WX_STRICT_ANSI_GCC__
172 #define wxCRT_StrdupA _strdup
173 #endif
174 #elif !defined(__WXWINCE__)
175 #define wxCRT_StrdupA strdup
176 #endif
177
178 /* most Windows compilers provide _wcsdup() */
179 #if defined(__WINDOWS__) && \
180 !(defined(__CYGWIN__) || defined(__WX_STRICT_ANSI_GCC__))
181 #define wxCRT_StrdupW _wcsdup
182 #elif defined(HAVE_WCSDUP)
183 #define wxCRT_StrdupW wcsdup
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
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 */
227 #if wxCHECK_VISUALC_VERSION(8) && (!defined(_WIN32_WCE) || (_WIN32_WCE >= 0x600))
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
237 #define wxCRT_StrnlenA strnlen
238 #endif
239
240 #ifdef HAVE_WCSNLEN
241 #define wxCRT_StrnlenW wcsnlen
242 #endif
243
244 /* define wxCRT_StricmpA/W and wxCRT_StrnicmpA/W for various compilers */
245
246 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
247 defined(__VISAGECPP__) || \
248 defined(__EMX__) || defined(__DJGPP__)
249 #define wxCRT_StricmpA stricmp
250 #define wxCRT_StrnicmpA strnicmp
251 #elif defined(__SYMANTEC__) || (defined(__VISUALC__) && !defined(__WXWINCE__))
252 #define wxCRT_StricmpA _stricmp
253 #define wxCRT_StrnicmpA _strnicmp
254 #elif defined(__UNIX__) || (defined(__GNUWIN32__) && !defined(__WX_STRICT_ANSI_GCC__))
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
266 #endif
267 #ifdef HAVE_WCSNCASECMP
268 #define wxCRT_StrnicmpW wcsncasecmp
269 #endif
270 /* #else -- use wxWidgets implementation */
271 #endif
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
280 extern "C" {
281 #endif
282
283 #ifndef wxCRT_StrlenW
284 WXDLLIMPEXP_BASE size_t wxCRT_StrlenW(const wchar_t *s);
285 #endif
286
287 #ifndef wxCRT_StrncmpW
288 WXDLLIMPEXP_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
309 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrcatW(wchar_t *dest, const wchar_t *src);
310 #endif
311
312 #ifndef wxCRT_StrchrW
313 WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrchrW(const wchar_t *s, wchar_t c);
314 #endif
315
316 #ifndef wxCRT_StrcmpW
317 WXDLLIMPEXP_BASE int wxCRT_StrcmpW(const wchar_t *s1, const wchar_t *s2);
318 #endif
319
320 #ifndef wxCRT_StrcollW
321 WXDLLIMPEXP_BASE int wxCRT_StrcollW(const wchar_t *s1, const wchar_t *s2);
322 #endif
323
324 #ifndef wxCRT_StrcpyW
325 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrcpyW(wchar_t *dest, const wchar_t *src);
326 #endif
327
328 #ifndef wxCRT_StrcspnW
329 WXDLLIMPEXP_BASE size_t wxCRT_StrcspnW(const wchar_t *s, const wchar_t *reject);
330 #endif
331
332 #ifndef wxCRT_StrncatW
333 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrncatW(wchar_t *dest, const wchar_t *src, size_t n);
334 #endif
335
336 #ifndef wxCRT_StrncpyW
337 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrncpyW(wchar_t *dest, const wchar_t *src, size_t n);
338 #endif
339
340 #ifndef wxCRT_StrpbrkW
341 WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrpbrkW(const wchar_t *s, const wchar_t *accept);
342 #endif
343
344 #ifndef wxCRT_StrrchrW
345 WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrrchrW(const wchar_t *s, wchar_t c);
346 #endif
347
348 #ifndef wxCRT_StrspnW
349 WXDLLIMPEXP_BASE size_t wxCRT_StrspnW(const wchar_t *s, const wchar_t *accept);
350 #endif
351
352 #ifndef wxCRT_StrstrW
353 WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrstrW(const wchar_t *haystack, const wchar_t *needle);
354 #endif
355
356 #ifndef wxCRT_StrtodW
357 WXDLLIMPEXP_BASE double wxCRT_StrtodW(const wchar_t *nptr, wchar_t **endptr);
358 #endif
359
360 #ifndef wxCRT_StrtolW
361 WXDLLIMPEXP_BASE long int wxCRT_StrtolW(const wchar_t *nptr, wchar_t **endptr, int base);
362 #endif
363
364 #ifndef wxCRT_StrtoulW
365 WXDLLIMPEXP_BASE unsigned long int wxCRT_StrtoulW(const wchar_t *nptr, wchar_t **endptr, int base);
366 #endif
367
368 #ifndef wxCRT_StrxfrmW
369 WXDLLIMPEXP_BASE size_t wxCRT_StrxfrmW(wchar_t *dest, const wchar_t *src, size_t n);
370 #endif
371
372 #ifndef wxCRT_StrdupA
373 WXDLLIMPEXP_BASE char *wxCRT_StrdupA(const char *psz);
374 #endif
375
376 #ifndef wxCRT_StrdupW
377 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrdupW(const wchar_t *pwz);
378 #endif
379
380 #ifndef wxCRT_StricmpA
381 WXDLLIMPEXP_BASE int wxCRT_StricmpA(const char *psz1, const char *psz2);
382 #endif
383
384 #ifndef wxCRT_StricmpW
385 WXDLLIMPEXP_BASE int wxCRT_StricmpW(const wchar_t *psz1, const wchar_t *psz2);
386 #endif
387
388 #ifndef wxCRT_StrnicmpA
389 WXDLLIMPEXP_BASE int wxCRT_StrnicmpA(const char *psz1, const char *psz2, size_t len);
390 #endif
391
392 #ifndef wxCRT_StrnicmpW
393 WXDLLIMPEXP_BASE int wxCRT_StrnicmpW(const wchar_t *psz1, const wchar_t *psz2, size_t len);
394 #endif
395
396 #ifndef wxCRT_StrtokA
397 WXDLLIMPEXP_BASE char *wxCRT_StrtokA(char *psz, const char *delim, char **save_ptr);
398 #endif
399
400 #ifndef wxCRT_StrtokW
401 WXDLLIMPEXP_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 */
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
422 #endif /* wxLongLong_t */
423
424
425 /* -------------------------------------------------------------------------
426 stdio.h
427 ------------------------------------------------------------------------- */
428
429 #if defined(__UNIX__) || defined(__WXMAC__)
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: */
438 #if wxMBFILES || !wxUSE_UNICODE /* ANSI filenames */
439
440 #define wxCRT_Fopen fopen
441 #define wxCRT_Freopen freopen
442 #define wxCRT_Remove remove
443 #define wxCRT_Rename rename
444
445 #else /* Unicode filenames */
446 /* special case: these functions are missing under Win9x with Unicows so we
447 have to implement them ourselves */
448 #if wxUSE_UNICODE_MSLU || defined(__WX_STRICT_ANSI_GCC__)
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
454 #define wxCRT_Freopen wxMSLU__wfreopen
455 #define wxCRT_Remove wxMSLU__wremove
456 #define wxCRT_Rename wxMSLU__wrename
457 #else
458 /* WinCE CRT doesn't provide these functions so use our own */
459 #ifdef __WXWINCE__
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);
463 #else
464 #define wxCRT_Rename _wrename
465 #define wxCRT_Remove _wremove
466 #endif
467 #define wxCRT_Fopen _wfopen
468 #define wxCRT_Freopen _wfreopen
469 #endif
470
471 #endif /* wxMBFILES/!wxMBFILES */
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
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
495
496 #ifndef wxCRT_PutsW
497 WXDLLIMPEXP_BASE int wxCRT_PutsW(const wchar_t *ws);
498 #endif
499
500 #ifndef wxCRT_FputsW
501 WXDLLIMPEXP_BASE int wxCRT_FputsW(const wchar_t *ch, FILE *stream);
502 #endif
503
504 #ifndef wxCRT_FputcW
505 WXDLLIMPEXP_BASE int wxCRT_FputcW(wchar_t wc, FILE *stream);
506 #endif
507
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
514
515 /* FIXME-CE: provide our own perror() using ::GetLastError() */
516 #ifndef __WXWINCE__
517
518 #define wxCRT_PerrorA perror
519 #ifdef wxHAVE_TCHAR_SUPPORT
520 #define wxCRT_PerrorW _wperror
521 #endif
522
523 #endif /* !__WXWINCE__ */
524
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... */
532 #define wxCRT_GetenvA(name) (name, NULL)
533 #define wxCRT_GetenvW(name) (name, NULL)
534 #else
535 #define wxCRT_GetenvA getenv
536 #ifdef _tgetenv
537 #define wxCRT_GetenvW _wgetenv
538 #endif
539 #endif
540
541 #ifndef wxCRT_GetenvW
542 WXDLLIMPEXP_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
556 #if defined(wxHAVE_TCHAR_SUPPORT) && !defined(__WX_STRICT_ANSI_GCC__)
557 #define wxCRT_AtoiW _wtoi
558 #define wxCRT_AtolW _wtol
559 /* _wtof doesn't exist */
560 #else
561 #ifndef __VMS
562 #define wxCRT_AtofW(s) wcstod(s, NULL)
563 #endif
564 #define wxCRT_AtolW(s) wcstol(s, NULL, 10)
565 /* wcstoi doesn't exist */
566 #endif
567
568 #ifdef __DARWIN__
569 #if !defined(__WXOSX_IPHONE__) && MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2
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
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 */
605 #ifdef __cplusplus
606 extern "C"
607 #endif
608 size_t
609 _xpg5_wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm * );
610 #define wxCRT_StrftimeW _xpg5_wcsftime
611 #else
612 /*
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).
616 */
617 #if defined(HAVE_WCSFTIME) || !defined(__UNIX__)
618 #define wxCRT_StrftimeW wcsftime
619 #endif
620 #endif
621
622 #ifndef wxCRT_StrftimeW
623 WXDLLIMPEXP_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
634 #ifdef __WATCOMC__
635 #define WXWCHAR_T_CAST(c) (wint_t)(c)
636 #else
637 #define WXWCHAR_T_CAST(c) c
638 #endif
639
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
663 #else /* !__GLIBC__ */
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))
668 #endif /* __GLIBC__/!__GLIBC__ */
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) */
685 inline size_t wxStrlen(const char *s) { return s ? wxCRT_StrlenA(s) : 0; }
686 inline size_t wxStrlen(const wchar_t *s) { return s ? wxCRT_StrlenW(s) : 0; }
687 #ifndef wxWCHAR_T_IS_WXCHAR16
688 WXDLLIMPEXP_BASE size_t wxStrlen(const wxChar16 *s );
689 #endif
690 #ifndef wxWCHAR_T_IS_WXCHAR32
691 WXDLLIMPEXP_BASE size_t wxStrlen(const wxChar32 *s );
692 #endif
693 #define wxWcslen wxCRT_StrlenW
694
695 #define wxStrdupA wxCRT_StrdupA
696 #define wxStrdupW wxCRT_StrdupW
697 inline char* wxStrdup(const char *s) { return wxCRT_StrdupA(s); }
698 inline wchar_t* wxStrdup(const wchar_t *s) { return wxCRT_StrdupW(s); }
699 #ifndef wxWCHAR_T_IS_WXCHAR16
700 WXDLLIMPEXP_BASE wxChar16* wxStrdup(const wxChar16* s);
701 #endif
702 #ifndef wxWCHAR_T_IS_WXCHAR32
703 WXDLLIMPEXP_BASE wxChar32* wxStrdup(const wxChar32* s);
704 #endif
705
706 #endif /* __cplusplus */
707
708 #endif /* _WX_WXCRTBASE_H_ */