always define wxLocaleIsUtf8
[wxWidgets.git] / include / wx / wxcrt.h
1 /*
2 * Name: wx/wxcrt.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_WXCRT_H_
16 #define _WX_WXCRT_H_
17
18 #include "wx/chartype.h"
19
20 #include <stdio.h> /* we use FILE below */
21
22 #ifdef __cplusplus
23 #if wxUSE_UNICODE_UTF8
24 // flag indicating whether the current locale uses UTF-8 or not; must be
25 // updated every time the locale is changed!
26 #if wxUSE_UTF8_LOCALE_ONLY
27 #define wxLocaleIsUtf8 true
28 #else
29 extern WXDLLIMPEXP_BASE bool wxLocaleIsUtf8;
30 #endif
31 // function used to update the flag:
32 extern WXDLLIMPEXP_BASE void wxUpdateLocaleIsUtf8();
33 #else // !wxUSE_UNICODE_UTF8
34 inline void wxUpdateLocaleIsUtf8() {}
35 #endif // wxUSE_UNICODE_UTF8/!wxUSE_UNICODE_UTF8
36 #endif // __cplusplus
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 /*
44 Standard headers we need here.
45
46 NB: don't include any wxWidgets headers here because almost all of them include
47 this one!
48 */
49
50 /* Almost all compiler have strdup(), but not quite all: CodeWarrior under Mac */
51 /* and VC++ for Windows CE don't provide it */
52 #if defined(__VISUALC__) && __VISUALC__ >= 1400
53 #define wxStrdupA _strdup
54 #elif !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
55 /* use #define, not inline wrapper, as it is tested with #ifndef below */
56 #define wxStrdupA strdup
57 #endif
58
59 #if defined(__MWERKS__)
60 /* Metrowerks only has wide char support for OS X >= 10.3 */
61 #if !defined(__DARWIN__) || \
62 (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)
63 #define wxHAVE_MWERKS_UNICODE
64 #endif
65
66 #ifdef wxHAVE_MWERKS_UNICODE
67 #define HAVE_WPRINTF 1
68 #define HAVE_WCSRTOMBS 1
69 #define HAVE_VSWPRINTF 1
70 #endif
71 #endif /* __MWERKS__ */
72
73 #ifdef wxHAVE_TCHAR_SUPPORT
74 /* we surely have wchar_t if we have TCHAR have wcslen() */
75 #ifndef HAVE_WCSLEN
76 #define HAVE_WCSLEN
77 #endif
78 #endif /* wxHAVE_TCHAR_SUPPORT */
79
80 /*
81 define wxFoo() function for each standard foo() function whose signature
82 (exceptionally including the return type) includes any mention of char:
83 wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
84 the same signature but with char replaced by wxChar which allows us to
85 use it in Unicode build as well
86 */
87
88 #ifdef wxHAVE_TCHAR_SUPPORT
89 #include <ctype.h>
90
91 #if defined(__WATCOMC__) && defined(UNICODE)
92 #define WXWCHAR_T_CAST(c) (wint_t)(c)
93 #else
94 #define WXWCHAR_T_CAST(c) c
95 #endif
96
97 /* ctype.h functions */
98 #define wxIsalnum(c) _istalnum(WXWCHAR_T_CAST(c))
99 #define wxIsalpha(c) _istalpha(WXWCHAR_T_CAST(c))
100 #define wxIscntrl(c) _istcntrl(WXWCHAR_T_CAST(c))
101 #define wxIsdigit(c) _istdigit(WXWCHAR_T_CAST(c))
102 #define wxIsgraph(c) _istgraph(WXWCHAR_T_CAST(c))
103 #define wxIslower(c) _istlower(WXWCHAR_T_CAST(c))
104 #define wxIsprint(c) _istprint(WXWCHAR_T_CAST(c))
105 #define wxIspunct(c) _istpunct(WXWCHAR_T_CAST(c))
106 #define wxIsspace(c) _istspace(WXWCHAR_T_CAST(c))
107 #define wxIsupper(c) _istupper(WXWCHAR_T_CAST(c))
108 #define wxIsxdigit(c) _istxdigit(WXWCHAR_T_CAST(c))
109
110 /*
111 There is a bug in VC6 C RTL: toxxx() functions dosn't do anything with
112 signed chars < 0, so "fix" it here.
113 */
114 #define wxTolower(c) _totlower((wxUChar)(wxChar)(c))
115 #define wxToupper(c) _totupper((wxUChar)(wxChar)(c))
116
117 /* locale.h functons */
118 #define wxSetlocale_ _tsetlocale
119
120 /* string.h functions */
121 #define wxStrcat _tcscat
122 #define wxStrchr _tcschr
123 #define wxStrcmp _tcscmp
124 #define wxStrcoll _tcscoll
125 #define wxStrcpy _tcscpy
126 #define wxStrcspn _tcscspn
127 #define wxStrdupW _wcsdup /* notice the 'W'! */
128 #define wxStrftime _tcsftime
129 #define wxStricmp _tcsicmp
130 #define wxStrnicmp _tcsnicmp
131 #define wxStrlen_ _tcslen /* used in wxStrlen inline function */
132 #define wxStrncat _tcsncat
133 #define wxStrncmp _tcsncmp
134 #define wxStrncpy _tcsncpy
135 #define wxStrpbrk _tcspbrk
136 #define wxStrrchr _tcsrchr
137 #define wxStrspn _tcsspn
138 #define wxStrstr _tcsstr
139 #define wxStrtod _tcstod
140 #define wxStrtol _tcstol
141 #define wxStrtoul _tcstoul
142 #ifdef __VISUALC__
143 #if __VISUALC__ >= 1300 && !defined(__WXWINCE__)
144 #define wxStrtoll _tcstoi64
145 #define wxStrtoull _tcstoui64
146 #endif /* VC++ 7+ */
147 #endif
148 #define wxStrxfrm _tcsxfrm
149
150 /* stdio.h functions */
151 #define wxFgetc _fgettc
152 #define wxFgetchar _fgettchar
153 #define wxFgets _fgetts
154 #if wxUSE_UNICODE_MSLU
155 WXDLLIMPEXP_BASE FILE * wxMSLU__tfopen(const wxChar *name, const wxChar *mode);
156
157 #define wxFopen wxMSLU__tfopen
158 #else
159 #define wxFopen _tfopen
160 #endif
161 #define wxFputc _fputtc
162 #define wxFputchar _fputtchar
163 #define wxFputs _fputts
164 #define wxFreopen _tfreopen
165 #define wxGetc _gettc
166 #define wxGetchar _gettchar
167 #define wxGets _getts
168 #define wxPerror _tperror
169 #define wxPutc(c,f) _puttc(WXWCHAR_T_CAST(c),f)
170 #define wxPutchar _puttchar
171 #define wxPuts _putts
172
173 #define wxTmpnam _ttmpnam
174 #define wxUngetc _tungetc
175
176 /* special case: these functions are missing under Win9x with Unicows so we */
177 /* have to implement them ourselves */
178 #if wxUSE_UNICODE_MSLU
179 WXDLLIMPEXP_BASE int wxMSLU__trename(const wxChar *oldname, const wxChar *newname);
180 WXDLLIMPEXP_BASE int wxMSLU__tremove(const wxChar *name);
181
182 #define wxRemove wxMSLU__tremove
183 #define wxRename wxMSLU__trename
184 #else
185 #ifdef __WXWINCE__
186 /* carefully: wxRemove() must return 0 on success while DeleteFile()
187 returns 0 on error, so don't just define one as the other */
188 int wxRemove(const wxChar *path);
189 #else
190 #define wxRemove _tremove
191 #define wxRename _trename
192 #endif
193 #endif
194
195 /* stdlib.h functions */
196 #define wxAtoi _ttoi
197 #define wxAtol _ttol
198 /* #define wxAtof _tttof -- notice that there is no such thing (why?) */
199 /* there are no env vars at all under CE, so no _tgetenv neither */
200 #ifdef __WXWINCE__
201 /* can't define as inline function as this is a C file... */
202 #define wxGetenv(name) ((wxChar *)NULL)
203 #else
204 #define wxGetenv _tgetenv
205 #endif
206 #define wxSystem _tsystem
207
208 /* time.h functions */
209 #define wxAsctime _tasctime
210 #define wxCtime _tctime
211
212 #define wxMbstowcs mbstowcs
213 #define wxWcstombs wcstombs
214 #else /* !TCHAR-aware compilers */
215 /*
216 There are 2 unrelated problems with these functions under Mac:
217 a) Metrowerks MSL CRT implements them strictly in C99 sense and
218 doesn't support (very common) extension of allowing to call
219 mbstowcs(NULL, ...) which makes it pretty useless as you can't
220 know the size of the needed buffer
221 b) OS X <= 10.2 declares and even defined these functions but
222 doesn't really implement them -- they always return an error
223
224 So use our own replacements in both cases.
225 */
226 #if defined(__MWERKS__) && defined(__MSL__)
227 #define wxNEED_WX_MBSTOWCS
228 #endif
229
230 #ifdef __DARWIN__
231 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2
232 #define wxNEED_WX_MBSTOWCS
233 #endif
234 #endif
235
236 #ifdef wxNEED_WX_MBSTOWCS
237 /* even though they are defined and "implemented", they are bad and just
238 stubs so we need our own - we need these even in ANSI builds!! */
239 WXDLLIMPEXP_BASE size_t wxMbstowcs (wchar_t *, const char *, size_t);
240 WXDLLIMPEXP_BASE size_t wxWcstombs (char *, const wchar_t *, size_t);
241 #else
242 #define wxMbstowcs mbstowcs
243 #define wxWcstombs wcstombs
244 #endif
245
246 /*
247 The system C library on Mac OS X 10.2 and below does not support
248 unicode: in other words all wide-character functions such as towupper et
249 al. do simply not exist so we need to provide our own in that context,
250 except for the wchar_t definition/typedef itself.
251
252 We need to do this for both project builder and CodeWarrior as
253 the latter uses the system C library in Mach builds for wide character
254 support, which as mentioned does not exist on 10.2 and below.
255 */
256 #if wxUSE_UNICODE && \
257 defined(__DARWIN__) && \
258 ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 )
259 /* we need everything! */
260 #define wxNEED_WX_STRING_H
261 #define wxNEED_WX_CTYPE_H
262
263 #define wxFgetchar(c) wxFgetc(c, stdin)
264 #define wxFputc wxPutc
265 #define wxFputchar(c) wxPutc(c, stdout)
266 #define wxGetc wxFgetc
267 #define wxGetchar(c) wxFgetc(c, stdin)
268
269 #include <stdio.h>
270
271 #define wxNEED_FGETC
272 #define wxNEED_FGETS
273 #define wxNEED_GETS
274 #define wxNEED_UNGETC
275
276 #define wxNEED_FPUTS
277 #define wxNEED_PUTS
278 #define wxNEED_PUTC
279
280 int wxFputs(const wxChar *ch, FILE *stream);
281 int wxPuts(const wxChar *ws);
282 int wxPutc(wxChar ch, FILE *stream);
283
284 #ifdef __cplusplus
285 extern "C" {
286 #endif
287 WXDLLIMPEXP_BASE size_t wxStrlen_(const wxChar *s);
288 #ifdef __cplusplus
289 }
290 #endif
291
292 #define wxPutchar(wch) wxPutc(wch, stdout)
293
294 #define wxNEED_PRINTF_CONVERSION
295 #define wxNEED_WX_STDIO_H
296 #define wxNEED_WX_STDLIB_H
297 #define wxNEED_WX_TIME_H
298
299 #elif wxUSE_UNICODE
300 #include <wctype.h>
301
302 /* this is probably glibc-specific */
303 #if defined(__WCHAR_TYPE__) && !defined(__MWERKS__)
304 /* ctype.h functions (wctype.h) */
305 #define wxIsalnum iswalnum
306 #define wxIsalpha iswalpha
307 #define wxIscntrl iswcntrl
308 #define wxIsdigit iswdigit
309 #define wxIsgraph iswgraph
310 #define wxIslower iswlower
311 #define wxIsprint iswprint
312 #define wxIspunct iswpunct
313 #define wxIsspace iswspace
314 #define wxIsupper iswupper
315 #define wxIsxdigit iswxdigit
316
317 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
318 /* /usr/include/wctype.h incorrectly declares translations */
319 /* tables which provokes tons of compile-time warnings -- try */
320 /* to correct this */
321 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
322 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
323 #else /* !glibc 2.0 */
324 #define wxTolower towlower
325 #define wxToupper towupper
326 #endif /* gcc/!gcc */
327
328 /* string.h functions (wchar.h) */
329 #define wxStrcat wcscat
330 #define wxStrchr wcschr
331 #define wxStrcmp wcscmp
332 #define wxStrcoll wcscoll
333 #define wxStrcpy wcscpy
334 #define wxStrcspn wcscspn
335 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
336 #define wxStrncat wcsncat
337 #define wxStrncmp wcsncmp
338 #define wxStrncpy wcsncpy
339 #define wxStrpbrk wcspbrk
340 #define wxStrrchr wcsrchr
341 #define wxStrspn wcsspn
342 #define wxStrstr wcsstr
343 #define wxStrtod wcstod
344 #define wxStrtol wcstol
345 #define wxStrtoul wcstoul
346 #ifdef HAVE_WCSTOULL
347 /* assume that we have wcstoull(), which is also C99, too */
348 #define wxStrtoll wcstoll
349 #define wxStrtoull wcstoull
350 #endif /* HAVE_WCSTOULL */
351 #define wxStrxfrm wcsxfrm
352
353 #define wxFgetc fgetwc
354 #define wxFgetchar fgetwchar
355 #define wxFgets fgetws
356 #define wxFputc fputwc
357 #define wxFputchar fputwchar
358 #define wxGetc getwc
359 #define wxGetchar getwchar
360 #define wxGets getws
361 #define wxUngetc ungetwc
362
363 #ifdef HAVE_FPUTWS
364 #define wxFputs fputws
365 #else
366 #define wxNEED_FPUTS
367 #include <stdio.h>
368 int wxFputs(const wxChar *ch, FILE *stream);
369 #endif
370
371 #ifdef HAVE_WPUTC
372 #define wxPutc wputc
373 #else
374 #define wxNEED_PUTC
375 #include <stdio.h>
376 int wxPutc(wxChar ch, FILE *stream);
377 #endif
378
379 #ifdef HAVE_WPUTCHAR
380 #define wxPutchar wputchar
381 #else
382 #define wxPutchar(wch) wxPutc(wch, stdout)
383 #endif
384
385 #ifdef HAVE_PUTWS
386 #define wxPuts putws
387 #else
388 #define wxNEED_PUTS
389 int wxPuts(const wxChar *ws);
390 #endif
391
392 /* we need %s to %ls conversion for printf and scanf etc */
393 #define wxNEED_PRINTF_CONVERSION
394
395 /* glibc doesn't have wide char equivalents of the other stuff so */
396 /* use our own versions */
397 #define wxNEED_WX_STDIO_H
398 #define wxNEED_WX_STDLIB_H
399 #define wxNEED_WX_TIME_H
400 #elif defined(__MWERKS__) && ( defined(__MSL__) || defined(__MACH__) )
401 /* ctype.h functions (wctype.h) */
402 #define wxIsalnum iswalnum
403 #define wxIsalpha iswalpha
404 #define wxIscntrl iswcntrl
405 #define wxIsdigit iswdigit
406 #define wxIsgraph iswgraph
407 #define wxIslower iswlower
408 #define wxIsprint iswprint
409 #define wxIspunct iswpunct
410 #define wxIsspace iswspace
411 #define wxIsupper iswupper
412 #define wxIsxdigit iswxdigit
413 #define wxTolower towlower
414 #define wxToupper towupper
415
416 /* string.h functions (wchar.h) */
417 #define wxStrcat wcscat
418 #define wxStrchr wcschr
419 #define wxStrcmp wcscmp
420 #define wxStrcoll wcscoll
421 #define wxStrcpy wcscpy
422 #define wxStrcspn wcscspn
423 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
424 #define wxStrncat wcsncat
425 #define wxStrncmp wcsncmp
426 #define wxStrncpy wcsncpy
427 #define wxStrpbrk wcspbrk
428 #define wxStrrchr wcsrchr
429 #define wxStrspn wcsspn
430 #define wxStrstr wcsstr
431 #define wxStrtod wcstod
432 #define wxStrtol wcstol
433 #define wxStrtoul wcstoul
434 #define wxStrxfrm wcsxfrm
435
436 #define wxFgetc fgetwc
437 #define wxFgetchar fgetwchar
438 #define wxFgets fgetws
439 #define wxFputc fputwc
440 #define wxFputchar fputwchar
441 #define wxGetc getwc
442 #define wxGetchar getwchar
443 #define wxGets getws
444 #define wxUngetc ungetwc
445
446 #define wxNEED_PRINTF_CONVERSION
447
448 #define wxPutc putwc
449 #define wxPutchar putwchar
450 #define wxFputs fputws
451
452 /* stdio.h functions */
453
454 #define wxNEED_WX_STDIO_H
455
456 /* stdlib.h functions */
457 #ifdef __MACH__
458 #define wxNEED_WX_STDLIB_H
459 #else
460 #define wxAtof watof
461 #define wxAtoi watoi
462 #define wxAtol watol
463 #define wxGetenv(a) ((wxChar*)NULL)
464 #define wxSystem(a) ((int)NULL)
465 #endif
466 /* time.h functions */
467 #define wxAsctime wasciitime
468 #define wxCtime wctime
469 /* #define wxStrftime wcsftime */
470
471 #define wxNEED_WX_TIME_H
472 #else /* !metrowerks for apple */
473 #error "Please define wide character functions for your environment"
474 #endif
475 #else /* ASCII */
476 #include <ctype.h>
477 #include <string.h>
478
479 /* ctype.h functions */
480 #define wxIsalnum isalnum
481 #define wxIsalpha isalpha
482 #define wxIscntrl iscntrl
483 #define wxIsdigit isdigit
484 #define wxIsgraph isgraph
485 #define wxIslower islower
486 #define wxIsprint isprint
487 #define wxIspunct ispunct
488 #define wxIsspace isspace
489 #define wxIsupper isupper
490 #define wxIsxdigit isxdigit
491 #define wxTolower tolower
492 #define wxToupper toupper
493
494 /* locale.h functons */
495 #define wxSetlocale_ setlocale
496
497 /* string.h functions */
498 #define wxStrcat strcat
499 #define wxStrchr strchr
500 #define wxStrcmp strcmp
501 #define wxStrcoll strcoll
502 #define wxStrcpy strcpy
503 #define wxStrcspn strcspn
504
505 /* wxStricmp and wxStrnicmp are defined below */
506 #define wxStrlen_ strlen /* used in wxStrlen inline function */
507 #define wxStrncat strncat
508 #define wxStrncmp strncmp
509 #define wxStrncpy strncpy
510 #define wxStrpbrk strpbrk
511 #define wxStrrchr strrchr
512 #define wxStrspn strspn
513 #define wxStrstr strstr
514 #define wxStrtod strtod
515 #ifdef HAVE_STRTOK_R
516 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
517 #endif
518 #define wxStrtol strtol
519 #define wxStrtoul strtoul
520 #ifdef HAVE_STRTOULL
521 /* assume that we have wcstoull(), which is also C99, too */
522 #define wxStrtoll strtoll
523 #define wxStrtoull strtoull
524 #endif /* HAVE_WCSTOULL */
525 #define wxStrxfrm strxfrm
526
527 /* stdio.h functions */
528 #define wxFopen fopen
529 #define wxFreopen freopen
530 #define wxRemove remove
531 #define wxRename rename
532
533 #define wxPerror perror
534 #define wxTmpnam tmpnam
535
536 #define wxFgetc fgetc
537 #define wxFgetchar fgetchar
538 #define wxFgets fgets
539 #define wxFputc fputc
540 #define wxFputs fputs
541 #define wxFputchar fputchar
542 #define wxGetc getc
543 #define wxGetchar getchar
544 #define wxGets gets
545 #define wxPutc putc
546 #define wxPutchar putchar
547 #define wxPuts puts
548 #define wxUngetc ungetc
549
550 /* stdlib.h functions */
551 #define wxAtof atof
552 #define wxAtoi atoi
553 #define wxAtol atol
554 #define wxGetenv getenv
555 #define wxSystem system
556
557 /* time.h functions */
558 #define wxAsctime asctime
559 #define wxCtime ctime
560 #define wxStrftime strftime
561 #endif /* Unicode/ASCII */
562 #endif /* TCHAR-aware compilers/the others */
563
564 /*
565 various special cases
566 */
567
568 /* define wxStricmp and wxStrnicmp for various compilers */
569
570 /* note that in Unicode mode we definitely are going to need our own version */
571 #if !defined(wxStricmp) && !wxUSE_UNICODE
572 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
573 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
574 defined(__EMX__) || defined(__DJGPP__)
575 #define wxStricmp stricmp
576 #define wxStrnicmp strnicmp
577 #elif defined(__WXPALMOS__)
578 /* FIXME: There is no equivalent to strnicmp in the Palm OS API. This
579 * quick hack should do until one can be written.
580 */
581 #define wxStricmp StrCaselessCompare
582 #define wxStrnicmp strnicmp
583 #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
584 (defined(__MWERKS__) && defined(__INTEL__))
585 #define wxStricmp _stricmp
586 #define wxStrnicmp _strnicmp
587 #elif defined(__UNIX__) || defined(__GNUWIN32__)
588 #define wxStricmp strcasecmp
589 #define wxStrnicmp strncasecmp
590 /* #else -- use wxWidgets implementation */
591 #endif
592 #endif /* !defined(wxStricmp) */
593
594 /* define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as */
595 /* it's used in wx/buffer.h -- and also might be used just below by wxStrlen() */
596 /* when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen) */
597 #if wxUSE_WCHAR_T
598 #ifdef HAVE_WCSLEN
599 #define wxWcslen wcslen
600 #else
601 WXDLLIMPEXP_BASE size_t wxWcslen(const wchar_t *s);
602 #endif
603 #endif /* wxUSE_WCHAR_T */
604
605 #ifdef __cplusplus
606 /* checks whether the passed in pointer is NULL and if the string is empty */
607 inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
608
609 /* safe version of strlen() (returns 0 if passed NULL pointer) */
610 inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
611 #endif
612
613 /*
614 each of strdup() and wcsdup() may or may not be available but we need both
615 of them anyhow for wx/buffer.h so we define the missing one(s) in
616 wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
617 defined -- if this is somehow not the case in some situations, please
618 correct that and not the lines here
619 */
620 #if wxUSE_UNICODE
621 #define wxStrdup wxStrdupW
622 #else
623 #define wxStrdup wxStrdupA
624 #endif
625
626 #ifdef __cplusplus
627 WXDLLIMPEXP_BASE bool wxOKlibc(); /* for internal use */
628 #endif
629
630 #ifndef wxStrtoll
631 /* supply strtoll and strtoull, if needed */
632 WXDLLIMPEXP_BASE wxLongLong_t wxStrtoll(const wxChar* nptr, wxChar** endptr, int base);
633 WXDLLIMPEXP_BASE wxULongLong_t wxStrtoull(const wxChar* nptr, wxChar** endptr, int base);
634 #endif
635
636 #define wxHAS_STRTOLL
637
638 /*
639 In Unicode mode we need to have all standard functions such as wprintf() and
640 so on but not all systems have them so use our own implementations in this
641 case.
642 */
643 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
644 #define wxNEED_WPRINTF
645 #endif
646
647 /*
648 various functions which might not be available in libc and for which we
649 provide our own replacements in wxchar.cpp
650 */
651
652 /* ctype.h functions */
653
654 /* RN: Used only under OSX <= 10.2 currently */
655 #ifdef wxNEED_WX_CTYPE_H
656 WXDLLIMPEXP_BASE int wxIsalnum(wxChar ch);
657 WXDLLIMPEXP_BASE int wxIsalpha(wxChar ch);
658 WXDLLIMPEXP_BASE int wxIscntrl(wxChar ch);
659 WXDLLIMPEXP_BASE int wxIsdigit(wxChar ch);
660 WXDLLIMPEXP_BASE int wxIsgraph(wxChar ch);
661 WXDLLIMPEXP_BASE int wxIslower(wxChar ch);
662 WXDLLIMPEXP_BASE int wxIsprint(wxChar ch);
663 WXDLLIMPEXP_BASE int wxIspunct(wxChar ch);
664 WXDLLIMPEXP_BASE int wxIsspace(wxChar ch);
665 WXDLLIMPEXP_BASE int wxIsupper(wxChar ch);
666 WXDLLIMPEXP_BASE int wxIsxdigit(wxChar ch);
667 WXDLLIMPEXP_BASE int wxTolower(wxChar ch);
668 WXDLLIMPEXP_BASE int wxToupper(wxChar ch);
669 #endif /* wxNEED_WX_CTYPE_H */
670
671 /* under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks */
672 /* the file parsing -- this may be true for 5.0 as well, update #ifdef then */
673 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
674 #undef wxIsspace
675 #define wxIsspace(c) ((((unsigned)(wxChar)c) < 128) && isspace(c))
676 #endif /* VC++ */
677
678 /*
679 a few compilers don't have the (non standard but common) isascii function,
680 define it ourselves for them
681 */
682 #ifndef isascii
683 #if defined(__MWERKS__)
684 #define wxNEED_ISASCII
685 #elif defined(_WIN32_WCE)
686 #if _WIN32_WCE <= 211
687 #define wxNEED_ISASCII
688 #endif
689 #endif
690 #endif /* isascii */
691
692 #ifdef wxNEED_ISASCII
693 inline int isascii(int c) { return (unsigned)c < 0x80; }
694 #endif
695
696 #ifdef _WIN32_WCE
697 #if _WIN32_WCE <= 211
698 #define isspace(c) ((c) == _T(' ') || (c) == _T('\t'))
699 #endif
700 #endif /* _WIN32_WCE */
701
702 /*
703 we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
704 initial versions of this header -- now it is too late to remove it so
705 although we fixed the function/macro name above, still provide the
706 backwards-compatible synonym.
707 */
708 #define wxIsctrl wxIscntrl
709
710 /* string.h functions */
711 #ifndef strdup
712 #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)
713 #define wxNEED_STRDUP
714 #elif defined(__WXWINCE__)
715 #if _WIN32_WCE <= 211
716 #define wxNEED_STRDUP
717 #endif
718 #endif
719 #endif /* strdup */
720
721 #ifdef wxNEED_STRDUP
722 WXDLLIMPEXP_BASE char *strdup(const char* s);
723 #endif
724
725 /* RN: Used only under OSX <= 10.2 currently
726 The __cplusplus ifdefs are messy, but they are required to build
727 the regex library, since c does not support function overloading
728 */
729 #ifdef wxNEED_WX_STRING_H
730 # ifdef __cplusplus
731 extern "C" {
732 # endif
733 WXDLLIMPEXP_BASE wxChar * wxStrcat(wxChar *dest, const wxChar *src);
734 WXDLLIMPEXP_BASE const wxChar * wxStrchr(const wxChar *s, wxChar c);
735 WXDLLIMPEXP_BASE int wxStrcmp(const wxChar *s1, const wxChar *s2);
736 WXDLLIMPEXP_BASE int wxStrcoll(const wxChar *s1, const wxChar *s2);
737 WXDLLIMPEXP_BASE wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
738 WXDLLIMPEXP_BASE size_t wxStrcspn(const wxChar *s, const wxChar *reject);
739 WXDLLIMPEXP_BASE wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
740 WXDLLIMPEXP_BASE int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
741 WXDLLIMPEXP_BASE wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
742 WXDLLIMPEXP_BASE const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
743 WXDLLIMPEXP_BASE const wxChar * wxStrrchr(const wxChar *s, wxChar c);
744 WXDLLIMPEXP_BASE size_t wxStrspn(const wxChar *s, const wxChar *accept);
745 WXDLLIMPEXP_BASE const wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
746 # ifdef __cplusplus
747 }
748 # endif
749
750 /* These functions use C++, so we can't c extern them */
751 WXDLLIMPEXP_BASE double wxStrtod(const wxChar *nptr, wxChar **endptr);
752 WXDLLIMPEXP_BASE long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
753 WXDLLIMPEXP_BASE unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
754 WXDLLIMPEXP_BASE size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
755
756 /* inlined versions */
757 #ifdef __cplusplus
758 inline wxChar * wxStrchr(wxChar *s, wxChar c)
759 { return (wxChar *)wxStrchr((const wxChar *)s, c); }
760 inline wxChar * wxStrpbrk(wxChar *s, const wxChar *accept)
761 { return (wxChar *)wxStrpbrk((const wxChar *)s, accept); }
762 inline wxChar * wxStrrchr(wxChar *s, wxChar c)
763 { return (wxChar *)wxStrrchr((const wxChar *)s, c); }
764 inline wxChar *wxStrstr(wxChar *haystack, const wxChar *needle)
765 { return (wxChar *)wxStrstr((const wxChar *)haystack, needle); }
766 #endif
767
768 #endif /* wxNEED_WX_STRING_H */
769
770 #ifndef wxStrdupA
771 WXDLLIMPEXP_BASE char *wxStrdupA(const char *psz);
772 #endif
773
774 #ifndef wxStrdupW
775 WXDLLIMPEXP_BASE wchar_t *wxStrdupW(const wchar_t *pwz);
776 #endif
777
778 #ifndef wxStricmp
779 WXDLLIMPEXP_BASE int wxStricmp(const wxChar *psz1, const wxChar *psz2);
780 #endif
781
782 #ifndef wxStrnicmp
783 WXDLLIMPEXP_BASE int wxStrnicmp(const wxChar *psz1, const wxChar *psz2, size_t len);
784 #endif
785
786 #ifndef wxStrtok
787 WXDLLIMPEXP_BASE wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
788 #endif
789
790 #ifdef __cplusplus
791 #ifndef wxSetlocale_
792 class WXDLLIMPEXP_BASE wxWCharBuffer;
793 WXDLLIMPEXP_BASE wxWCharBuffer wxSetlocale_(int category, const wxChar *locale);
794 WXDLLIMPEXP_BASE wxWCharBuffer wxSetlocale(int category, const wxChar *locale);
795 #else
796 WXDLLIMPEXP_BASE wxChar *wxSetlocale(int category, const wxChar *locale);
797 #endif // defined(wxSetlocale_)
798 #endif // __cplusplus
799
800 /* stdio.h functions */
801 #ifdef wxNEED_WX_STDIO_H
802 #include <stdio.h>
803 WXDLLIMPEXP_BASE FILE * wxFopen(const wxChar *path, const wxChar *mode);
804 WXDLLIMPEXP_BASE FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
805 WXDLLIMPEXP_BASE int wxRemove(const wxChar *path);
806 WXDLLIMPEXP_BASE int wxRename(const wxChar *oldpath, const wxChar *newpath);
807
808 /* *printf() family is handled separately */
809 #endif /* wxNEED_WX_STDIO_H */
810
811
812 /* stdlib.h functions */
813 #ifndef wxAtof
814 WXDLLIMPEXP_BASE double wxAtof(const wxChar *psz);
815 #endif
816
817 #ifdef wxNEED_WX_STDLIB_H
818 WXDLLIMPEXP_BASE int wxAtoi(const wxChar *psz);
819 WXDLLIMPEXP_BASE long wxAtol(const wxChar *psz);
820 WXDLLIMPEXP_BASE wxChar * wxGetenv(const wxChar *name);
821 WXDLLIMPEXP_BASE int wxSystem(const wxChar *psz);
822 #endif
823
824
825 /* time.h functions */
826 #ifdef wxNEED_WX_TIME_H
827 #if defined(__MWERKS__) && defined(macintosh)
828 #include <time.h>
829 #endif
830 /*silent gabby compilers*/
831 struct tm;
832 WXDLLIMPEXP_BASE size_t wxStrftime(wxChar *s, size_t max,
833 const wxChar *fmt,
834 const struct tm *tm);
835 #endif /* wxNEED_WX_TIME_H */
836
837 #ifndef wxCtime
838 #include <time.h>
839 WXDLLIMPEXP_BASE wxChar *wxCtime(const time_t *timep);
840 #endif
841
842
843 /* missing functions in some WinCE versions */
844 #ifdef _WIN32_WCE
845 #if (_WIN32_WCE < 300)
846 WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size );
847 #endif
848 #endif /* _WIN32_WCE */
849
850 /* multibyte to wide char conversion functions and macros */
851
852 #if wxUSE_WCHAR_T
853 /* multibyte<->widechar conversion */
854 WXDLLIMPEXP_BASE size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
855 WXDLLIMPEXP_BASE size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
856
857 #if wxUSE_UNICODE
858 #define wxMB2WX wxMB2WC
859 #define wxWX2MB wxWC2MB
860 #define wxWC2WX wxStrncpy
861 #define wxWX2WC wxStrncpy
862 #else
863 #define wxMB2WX wxStrncpy
864 #define wxWX2MB wxStrncpy
865 #define wxWC2WX wxWC2MB
866 #define wxWX2WC wxMB2WC
867 #endif
868 #else /* !wxUSE_UNICODE */
869 /* Why is this here?
870 #error ha */
871 /* No wxUSE_WCHAR_T: we have to do something (JACS) */
872 #define wxMB2WC wxStrncpy
873 #define wxWC2MB wxStrncpy
874 #define wxMB2WX wxStrncpy
875 #define wxWX2MB wxStrncpy
876 #define wxWC2WX wxWC2MB
877 #define wxWX2WC wxMB2WC
878 #endif
879
880 /*
881 RN: The following are not normal versions of memcpy et al., rather
882 these are either char or widechar versions depending on
883 if unicode is used or not.
884 */
885
886 #ifdef __cplusplus
887
888 //
889 // RN: We could do the usual tricky compiler detection here,
890 // and use their variant (such as wmemchr, etc.). The problem
891 // is that these functions are quite rare, even though they are
892 // part of the current POSIX standard. In addition, most compilers
893 // (including even MSC) inline them just like we do right in their
894 // headers.
895 //
896 #if wxUSE_UNICODE
897 #include <string.h> //for mem funcs
898
899 //implement our own wmem variants
900 inline wxChar* wxTmemchr(const wxChar* s, wxChar c, size_t l)
901 {
902 for(;l && *s != c;--l, ++s) {}
903
904 if(l)
905 return (wxChar*)s;
906 return NULL;
907 }
908
909 inline int wxTmemcmp(const wxChar* sz1, const wxChar* sz2, size_t len)
910 {
911 for(; *sz1 == *sz2 && len; --len, ++sz1, ++sz2) {}
912
913 if(len)
914 return *sz1 < *sz2 ? -1 : *sz1 > *sz2;
915 else
916 return 0;
917 }
918
919 inline wxChar* wxTmemcpy(wxChar* szOut, const wxChar* szIn, size_t len)
920 {
921 return (wxChar*) memcpy(szOut, szIn, len * sizeof(wxChar));
922 }
923
924 inline wxChar* wxTmemmove(wxChar* szOut, const wxChar* szIn, size_t len)
925 {
926 return (wxChar*) memmove(szOut, szIn, len * sizeof(wxChar));
927 }
928
929 inline wxChar* wxTmemset(wxChar* szOut, const wxChar cIn, size_t len)
930 {
931 wxChar* szRet = szOut;
932
933 while (len--)
934 *szOut++ = cIn;
935
936 return szRet;
937 }
938
939 #else /* !wxUSE_UNICODE */
940 # define wxTmemchr memchr
941 # define wxTmemcmp memcmp
942 # define wxTmemcpy memcpy
943 # define wxTmemmove memmove
944 # define wxTmemset memset
945 #endif /* wxUSE_UNICODE/!wxUSE_UNICODE */
946
947 #endif /*__cplusplus*/
948
949 #endif /* _WX_WXCRT_H_ */