]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxcrtbase.h
Fix setting frame icon when using non-standard icon sizes in wxMSW.
[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 * 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 NB2: User code should include wx/crt.h instead of including this
31 header directly.
32
33 */
34
35 #include <stdio.h>
36 #include <string.h>
37 #include <ctype.h>
38 #include <wctype.h>
39 #include <time.h>
40
41 #if defined(__WINDOWS__) && !defined(__WXWINCE__)
42 #include <io.h>
43 #endif
44
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 **);
47 #endif
48
49 /*
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
55 ANSI mode.
56 */
57 #if defined(__MINGW32__) && defined(__STRICT_ANSI__)
58 #define __WX_STRICT_ANSI_GCC__
59 #endif
60
61 /*
62 a few compilers don't have the (non standard but common) isascii function,
63 define it ourselves for them
64 */
65 #ifndef isascii
66 #if defined(__MWERKS__) || defined(__WX_STRICT_ANSI_GCC__)
67 #define wxNEED_ISASCII
68 #elif defined(_WIN32_WCE)
69 #if _WIN32_WCE <= 211
70 #define wxNEED_ISASCII
71 #endif
72 #endif
73 #endif /* isascii */
74
75 #ifdef wxNEED_ISASCII
76 inline int isascii(int c) { return (unsigned)c < 0x80; }
77 #endif
78
79 #ifdef _WIN32_WCE
80 #if _WIN32_WCE <= 211
81 #define isspace(c) ((c) == wxT(' ') || (c) == wxT('\t'))
82 #endif
83 #endif /* _WIN32_WCE */
84
85 /* string.h functions */
86 #ifndef strdup
87 #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)
88 #define wxNEED_STRDUP
89 #elif defined(__WXWINCE__)
90 #if _WIN32_WCE <= 211
91 #define wxNEED_STRDUP
92 #endif
93 #endif
94 #endif /* strdup */
95
96 #ifdef wxNEED_STRDUP
97 WXDLLIMPEXP_BASE char *strdup(const char* s);
98 #endif
99
100 /* missing functions in some WinCE versions */
101 #ifdef _WIN32_WCE
102 #if (_WIN32_WCE < 300)
103 WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size );
104 #endif
105 #endif /* _WIN32_WCE */
106
107
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
113 #endif
114
115 #ifdef wxHAVE_MWERKS_UNICODE
116 #define HAVE_WPRINTF 1
117 #define HAVE_WCSRTOMBS 1
118 #define HAVE_VSWPRINTF 1
119 #endif
120 #endif /* __MWERKS__ */
121
122
123 /* -------------------------------------------------------------------------
124 UTF-8 locale handling
125 ------------------------------------------------------------------------- */
126
127 #ifdef __cplusplus
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
133 #else
134 extern WXDLLIMPEXP_BASE bool wxLocaleIsUtf8;
135 #endif
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 */
142
143
144 /* -------------------------------------------------------------------------
145 string.h
146 ------------------------------------------------------------------------- */
147
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
161
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
174
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
179
180 #define wxCRT_StrcollW wcscoll
181 #define wxCRT_StrxfrmW wcsxfrm
182 #endif /* __WXWINCE__ */
183
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) || \
190 defined(__MINGW32__)
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
196 #endif
197
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
204 #endif
205
206 #ifdef wxHAVE_TCHAR_SUPPORT
207 /* we surely have wchar_t if we have TCHAR have wcslen() */
208 #ifndef HAVE_WCSLEN
209 #define HAVE_WCSLEN
210 #endif
211 #endif /* wxHAVE_TCHAR_SUPPORT */
212
213 #ifdef HAVE_WCSLEN
214 #define wxCRT_StrlenW wcslen
215 #endif
216
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
223
224 #ifdef __VISUALC__
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
230 #endif /* VC++ 7+ */
231 #else
232 #ifdef HAVE_STRTOULL
233 #define wxCRT_StrtollA strtoll
234 #define wxCRT_StrtoullA strtoull
235 #endif /* HAVE_STRTOULL */
236 #ifdef HAVE_WCSTOULL
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 */
241 #endif
242
243 /*
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.
246 */
247 #if wxCHECK_VISUALC_VERSION(8) && (!defined(_WIN32_WCE) || (_WIN32_WCE >= 0x600))
248 #ifndef HAVE_STRNLEN
249 #define HAVE_STRNLEN
250 #endif
251 #ifndef HAVE_WCSNLEN
252 #define HAVE_WCSNLEN
253 #endif
254 #endif
255
256 #ifdef HAVE_STRNLEN
257 #define wxCRT_StrnlenA strnlen
258 #endif
259
260 #ifdef HAVE_WCSNLEN
261 #define wxCRT_StrnlenW wcsnlen
262 #endif
263
264 /* define wxCRT_StricmpA/W and wxCRT_StrnicmpA/W for various compilers */
265
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 */
279 #endif
280
281 #ifdef __VISUALC__
282 #define wxCRT_StricmpW _wcsicmp
283 #define wxCRT_StrnicmpW _wcsnicmp
284 #elif defined(__UNIX__)
285 #ifdef HAVE_WCSCASECMP
286 #define wxCRT_StricmpW wcscasecmp
287 #endif
288 #ifdef HAVE_WCSNCASECMP
289 #define wxCRT_StrnicmpW wcsncasecmp
290 #endif
291 /* #else -- use wxWidgets implementation */
292 #endif
293
294 #ifdef HAVE_STRTOK_R
295 #define wxCRT_StrtokA(str, sep, last) strtok_r(str, sep, last)
296 #endif
297 /* FIXME-UTF8: detect and use wcstok() if available for wxCRT_StrtokW */
298
299 /* these are extern "C" because they are used by regex lib: */
300 #ifdef __cplusplus
301 extern "C" {
302 #endif
303
304 #ifndef wxCRT_StrlenW
305 WXDLLIMPEXP_BASE size_t wxCRT_StrlenW(const wchar_t *s);
306 #endif
307
308 #ifndef wxCRT_StrncmpW
309 WXDLLIMPEXP_BASE int wxCRT_StrncmpW(const wchar_t *s1, const wchar_t *s2, size_t n);
310 #endif
311
312 #ifdef __cplusplus
313 }
314 #endif
315
316 /* FIXME-UTF8: remove this once we are Unicode only */
317 #if wxUSE_UNICODE
318 #define wxCRT_StrlenNative wxCRT_StrlenW
319 #define wxCRT_StrncmpNative wxCRT_StrncmpW
320 #define wxCRT_ToupperNative wxCRT_ToupperW
321 #define wxCRT_TolowerNative wxCRT_TolowerW
322 #else
323 #define wxCRT_StrlenNative wxCRT_StrlenA
324 #define wxCRT_StrncmpNative wxCRT_StrncmpA
325 #define wxCRT_ToupperNative toupper
326 #define wxCRT_TolowerNative tolower
327 #endif
328
329 #ifndef wxCRT_StrcatW
330 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrcatW(wchar_t *dest, const wchar_t *src);
331 #endif
332
333 #ifndef wxCRT_StrchrW
334 WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrchrW(const wchar_t *s, wchar_t c);
335 #endif
336
337 #ifndef wxCRT_StrcmpW
338 WXDLLIMPEXP_BASE int wxCRT_StrcmpW(const wchar_t *s1, const wchar_t *s2);
339 #endif
340
341 #ifndef wxCRT_StrcollW
342 WXDLLIMPEXP_BASE int wxCRT_StrcollW(const wchar_t *s1, const wchar_t *s2);
343 #endif
344
345 #ifndef wxCRT_StrcpyW
346 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrcpyW(wchar_t *dest, const wchar_t *src);
347 #endif
348
349 #ifndef wxCRT_StrcspnW
350 WXDLLIMPEXP_BASE size_t wxCRT_StrcspnW(const wchar_t *s, const wchar_t *reject);
351 #endif
352
353 #ifndef wxCRT_StrncatW
354 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrncatW(wchar_t *dest, const wchar_t *src, size_t n);
355 #endif
356
357 #ifndef wxCRT_StrncpyW
358 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrncpyW(wchar_t *dest, const wchar_t *src, size_t n);
359 #endif
360
361 #ifndef wxCRT_StrpbrkW
362 WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrpbrkW(const wchar_t *s, const wchar_t *accept);
363 #endif
364
365 #ifndef wxCRT_StrrchrW
366 WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrrchrW(const wchar_t *s, wchar_t c);
367 #endif
368
369 #ifndef wxCRT_StrspnW
370 WXDLLIMPEXP_BASE size_t wxCRT_StrspnW(const wchar_t *s, const wchar_t *accept);
371 #endif
372
373 #ifndef wxCRT_StrstrW
374 WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrstrW(const wchar_t *haystack, const wchar_t *needle);
375 #endif
376
377 #ifndef wxCRT_StrtodW
378 WXDLLIMPEXP_BASE double wxCRT_StrtodW(const wchar_t *nptr, wchar_t **endptr);
379 #endif
380
381 #ifndef wxCRT_StrtolW
382 WXDLLIMPEXP_BASE long int wxCRT_StrtolW(const wchar_t *nptr, wchar_t **endptr, int base);
383 #endif
384
385 #ifndef wxCRT_StrtoulW
386 WXDLLIMPEXP_BASE unsigned long int wxCRT_StrtoulW(const wchar_t *nptr, wchar_t **endptr, int base);
387 #endif
388
389 #ifndef wxCRT_StrxfrmW
390 WXDLLIMPEXP_BASE size_t wxCRT_StrxfrmW(wchar_t *dest, const wchar_t *src, size_t n);
391 #endif
392
393 #ifndef wxCRT_StrdupA
394 WXDLLIMPEXP_BASE char *wxCRT_StrdupA(const char *psz);
395 #endif
396
397 #ifndef wxCRT_StrdupW
398 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrdupW(const wchar_t *pwz);
399 #endif
400
401 #ifndef wxCRT_StricmpA
402 WXDLLIMPEXP_BASE int wxCRT_StricmpA(const char *psz1, const char *psz2);
403 #endif
404
405 #ifndef wxCRT_StricmpW
406 WXDLLIMPEXP_BASE int wxCRT_StricmpW(const wchar_t *psz1, const wchar_t *psz2);
407 #endif
408
409 #ifndef wxCRT_StrnicmpA
410 WXDLLIMPEXP_BASE int wxCRT_StrnicmpA(const char *psz1, const char *psz2, size_t len);
411 #endif
412
413 #ifndef wxCRT_StrnicmpW
414 WXDLLIMPEXP_BASE int wxCRT_StrnicmpW(const wchar_t *psz1, const wchar_t *psz2, size_t len);
415 #endif
416
417 #ifndef wxCRT_StrtokA
418 WXDLLIMPEXP_BASE char *wxCRT_StrtokA(char *psz, const char *delim, char **save_ptr);
419 #endif
420
421 #ifndef wxCRT_StrtokW
422 WXDLLIMPEXP_BASE wchar_t *wxCRT_StrtokW(wchar_t *psz, const wchar_t *delim, wchar_t **save_ptr);
423 #endif
424
425 /* supply strtoll and strtoull, if needed */
426 #ifdef wxLongLong_t
427 #ifndef wxCRT_StrtollA
428 WXDLLIMPEXP_BASE wxLongLong_t wxCRT_StrtollA(const char* nptr,
429 char** endptr,
430 int base);
431 WXDLLIMPEXP_BASE wxULongLong_t wxCRT_StrtoullA(const char* nptr,
432 char** endptr,
433 int base);
434 #endif
435 #ifndef wxCRT_StrtollW
436 WXDLLIMPEXP_BASE wxLongLong_t wxCRT_StrtollW(const wchar_t* nptr,
437 wchar_t** endptr,
438 int base);
439 WXDLLIMPEXP_BASE wxULongLong_t wxCRT_StrtoullW(const wchar_t* nptr,
440 wchar_t** endptr,
441 int base);
442 #endif
443 #endif /* wxLongLong_t */
444
445
446 /* -------------------------------------------------------------------------
447 stdio.h
448 ------------------------------------------------------------------------- */
449
450 #if defined(__UNIX__) || defined(__WXMAC__)
451 #define wxMBFILES 1
452 #else
453 #define wxMBFILES 0
454 #endif
455
456
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 */
460
461 #define wxCRT_Fopen fopen
462 #define wxCRT_Freopen freopen
463 #define wxCRT_Remove remove
464 #define wxCRT_Rename rename
465
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
478 #else
479 /* WinCE CRT doesn't provide these functions so use our own */
480 #ifdef __WXWINCE__
481 WXDLLIMPEXP_BASE int wxCRT_Rename(const wchar_t *src,
482 const wchar_t *dst);
483 WXDLLIMPEXP_BASE int wxCRT_Remove(const wchar_t *path);
484 #else
485 #define wxCRT_Rename _wrename
486 #define wxCRT_Remove _wremove
487 #endif
488 #define wxCRT_Fopen _wfopen
489 #define wxCRT_Freopen _wfreopen
490 #endif
491
492 #endif /* wxMBFILES/!wxMBFILES */
493
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
500
501 #ifdef wxHAVE_TCHAR_SUPPORT
502 #define wxCRT_PutsW _putws
503 #define wxCRT_FputsW fputws
504 #define wxCRT_FputcW fputwc
505 #endif
506 #ifdef HAVE_FPUTWS
507 #define wxCRT_FputsW fputws
508 #endif
509 #ifdef HAVE_PUTWS
510 #define wxCRT_PutsW putws
511 #endif
512 #ifdef HAVE_FPUTWC
513 #define wxCRT_FputcW fputwc
514 #endif
515 #define wxCRT_FgetsW fgetws
516
517 #ifndef wxCRT_PutsW
518 WXDLLIMPEXP_BASE int wxCRT_PutsW(const wchar_t *ws);
519 #endif
520
521 #ifndef wxCRT_FputsW
522 WXDLLIMPEXP_BASE int wxCRT_FputsW(const wchar_t *ch, FILE *stream);
523 #endif
524
525 #ifndef wxCRT_FputcW
526 WXDLLIMPEXP_BASE int wxCRT_FputcW(wchar_t wc, FILE *stream);
527 #endif
528
529 /*
530 NB: tmpnam() is unsafe and thus is not wrapped!
531 Use other wxWidgets facilities instead:
532 wxFileName::CreateTempFileName, wxTempFile, or wxTempFileOutputStream
533 */
534 #define wxTmpnam(x) wxTmpnam_is_insecure_use_wxTempFile_instead
535
536 /* FIXME-CE: provide our own perror() using ::GetLastError() */
537 #ifndef __WXWINCE__
538
539 #define wxCRT_PerrorA perror
540 #ifdef wxHAVE_TCHAR_SUPPORT
541 #define wxCRT_PerrorW _wperror
542 #endif
543
544 #endif /* !__WXWINCE__ */
545
546 /* -------------------------------------------------------------------------
547 stdlib.h
548 ------------------------------------------------------------------------- */
549
550 /* there are no env vars at all under CE, so no _tgetenv neither */
551 #ifdef __WXWINCE__
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)
555 #else
556 #define wxCRT_GetenvA getenv
557 #ifdef _tgetenv
558 #define wxCRT_GetenvW _wgetenv
559 #endif
560 #endif
561
562 #ifndef wxCRT_GetenvW
563 WXDLLIMPEXP_BASE wchar_t * wxCRT_GetenvW(const wchar_t *name);
564 #endif
565
566
567 #define wxCRT_SystemA system
568 /* mingw32 doesn't provide _tsystem() or _wsystem(): */
569 #if defined(_tsystem)
570 #define wxCRT_SystemW _wsystem
571 #endif
572
573 #define wxCRT_AtofA atof
574 #define wxCRT_AtoiA atoi
575 #define wxCRT_AtolA atol
576
577 #if defined(__MWERKS__)
578 #if defined(__MSL__)
579 #define wxCRT_AtofW watof
580 #define wxCRT_AtoiW watoi
581 #define wxCRT_AtolW watol
582 /* else: use ANSI versions */
583 #endif
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 */
588 #else
589 #ifndef __VMS
590 #define wxCRT_AtofW(s) wcstod(s, NULL)
591 #endif
592 #define wxCRT_AtolW(s) wcstol(s, NULL, 10)
593 /* wcstoi doesn't exist */
594 #endif
595
596 /*
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
604
605 So use our own replacements in both cases.
606 */
607 #if defined(__MWERKS__) && defined(__MSL__)
608 #define wxNEED_WX_MBSTOWCS
609 #endif
610
611 #ifdef __DARWIN__
612 #if !defined(__WXOSX_IPHONE__) && MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2
613 #define wxNEED_WX_MBSTOWCS
614 #endif
615 #endif
616
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);
622 #else
623 #define wxMbstowcs mbstowcs
624 #define wxWcstombs wcstombs
625 #endif
626
627
628
629 /* -------------------------------------------------------------------------
630 time.h
631 ------------------------------------------------------------------------- */
632
633 #define wxCRT_StrftimeA strftime
634 #ifdef __SGI__
635 /*
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).
647 */
648 #ifdef __cplusplus
649 extern "C"
650 #endif
651 size_t
652 _xpg5_wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm * );
653 #define wxCRT_StrftimeW _xpg5_wcsftime
654 #else
655 /*
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).
659 */
660 #if defined(HAVE_WCSFTIME) || !defined(__UNIX__)
661 #define wxCRT_StrftimeW wcsftime
662 #endif
663 #endif
664
665 #ifndef wxCRT_StrftimeW
666 WXDLLIMPEXP_BASE size_t wxCRT_StrftimeW(wchar_t *s, size_t max,
667 const wchar_t *fmt,
668 const struct tm *tm);
669 #endif
670
671
672
673 /* -------------------------------------------------------------------------
674 ctype.h
675 ------------------------------------------------------------------------- */
676
677 #ifdef __WATCOMC__
678 #define WXWCHAR_T_CAST(c) (wint_t)(c)
679 #else
680 #define WXWCHAR_T_CAST(c) c
681 #endif
682
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))
694
695 #ifdef __GLIBC__
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
705 #endif
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__ */
712
713
714
715
716
717 /* -------------------------------------------------------------------------
718 wx wrappers for CRT functions in both char* and wchar_t* versions
719 ------------------------------------------------------------------------- */
720
721 #ifdef __cplusplus
722
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: */
726
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 );
732 #endif
733 #ifndef wxWCHAR_T_IS_WXCHAR32
734 WXDLLIMPEXP_BASE size_t wxStrlen(const wxChar32 *s );
735 #endif
736 #define wxWcslen wxCRT_StrlenW
737
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);
744 #endif
745 #ifndef wxWCHAR_T_IS_WXCHAR32
746 WXDLLIMPEXP_BASE wxChar32* wxStrdup(const wxChar32* s);
747 #endif
748
749 #endif /* __cplusplus */
750
751 #endif /* _WX_WXCRTBASE_H_ */