3 * Purpose: Declarations common to wx char/wchar_t usage (wide chars)
4 * Author: Joel Farley, Ove Kåven
5 * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee
8 * Copyright: (c) 1998-2006 wxWidgets dev team
9 * Licence: wxWindows licence
12 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
17 /* defs.h indirectly includes this file, so don't include it here */
18 #include "wx/platform.h"
19 #include "wx/dlimpexp.h"
21 #if defined(HAVE_STRTOK_R) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
22 char *strtok_r(char *, const char *, char **);
25 /* check whether we have wchar_t and which size it is if we do */
26 #if !defined(wxUSE_WCHAR_T)
28 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
29 #define wxUSE_WCHAR_T 1
31 #define wxUSE_WCHAR_T 0
33 #elif defined(__GNUWIN32__) && !defined(__MINGW32__)
34 #define wxUSE_WCHAR_T 0
35 #elif defined(__WATCOMC__)
36 #define wxUSE_WCHAR_T 0
37 #elif defined(__VISAGECPP__) && (__IBMCPP__ < 400)
38 #define wxUSE_WCHAR_T 0
40 /* add additional compiler checks if this fails */
41 #define wxUSE_WCHAR_T 1
43 #endif /* !defined(wxUSE_WCHAR_T) */
45 /* Unicode support requires wchar_t */
46 #if wxUSE_UNICODE && !wxUSE_WCHAR_T
47 #error "wchar_t must be available in Unicode build"
51 Standard headers we need here.
53 NB: don't include any wxWidgets headers here because almost all of them include
57 /* Required for wxPrintf() etc */
60 /* Almost all compiler have strdup(), but not quite all: CodeWarrior under Mac */
61 /* and VC++ for Windows CE don't provide it */
62 #if defined(__VISUALC__) && __VISUALC__ >= 1400
63 #define wxStrdupA _strdup
64 #elif !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
65 /* use #define, not inline wrapper, as it is tested with #ifndef below */
66 #define wxStrdupA strdup
70 non Unix compilers which do have wchar.h (but not tchar.h which is included
71 below and which includes wchar.h anyhow).
73 Actually MinGW has tchar.h, but it does not include wchar.h
75 #if defined(__MWERKS__) || defined(__VISAGECPP__) || defined(__MINGW32__) || defined(__WATCOMC__)
80 #if defined(__MWERKS__) && !defined(__MACH__)
88 /* the current (as of Nov 2002) version of cygwin has a bug in its */
89 /* wchar.h -- there is no extern "C" around the declarations in it and */
90 /* this results in linking errors later; also, at least on some */
91 /* Cygwin versions, wchar.h requires sys/types.h */
93 #include <sys/types.h>
101 #if defined(__CYGWIN__) && defined(__cplusplus)
103 #endif /* Cygwin and C++ */
105 #elif defined(HAVE_WCSTR_H)
106 /* old compilers have relevant declarations here */
108 #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
109 /* include stdlib.h for wchar_t */
111 #endif /* HAVE_WCHAR_H */
112 #endif /* wxUSE_WCHAR_T */
114 /* ---------------------------------------------------------------------------- */
115 /* define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type */
116 /* mapped to either char or wchar_t depending on the ASCII/Unicode mode and have */
117 /* the function mapping _tfoo() -> foo() or wfoo() */
118 /* ---------------------------------------------------------------------------- */
120 /* VC++ and BC++ starting with 5.2 have TCHAR support */
122 #define wxHAVE_TCHAR_SUPPORT
123 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
124 #define wxHAVE_TCHAR_SUPPORT
126 #elif defined(__WATCOMC__)
127 #define wxHAVE_TCHAR_SUPPORT
128 #elif defined(__DMC__)
129 #define wxHAVE_TCHAR_SUPPORT
130 #elif defined(__WXPALMOS__)
132 #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
133 #define wxHAVE_TCHAR_SUPPORT
137 #elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
138 /* VZ: the old VisualAge definitions were completely wrong and had no */
139 /* chance at all to work in Unicode build anyhow so let's pretend that */
140 /* VisualAge does _not_ support TCHAR for the moment (as indicated by */
141 /* "0 &&" above) until someone really has time to delve into Unicode */
142 /* issues under OS/2 */
144 /* VisualAge 4.0+ supports TCHAR */
145 #define wxHAVE_TCHAR_SUPPORT
146 #endif /* compilers with (good) TCHAR support */
148 #if defined(__MWERKS__)
149 /* Metrowerks only has wide char support for OS X >= 10.3 */
150 #if !defined(__DARWIN__) || \
151 (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)
152 #define wxHAVE_MWERKS_UNICODE
155 #ifdef wxHAVE_MWERKS_UNICODE
156 #define HAVE_WPRINTF 1
157 #define HAVE_WCSRTOMBS 1
158 #define HAVE_VSWPRINTF 1
160 #endif /* __MWERKS__ */
162 #ifdef wxHAVE_TCHAR_SUPPORT
163 /* get TCHAR definition if we've got it */
166 /* we surely do have wchar_t if we have TCHAR */
167 #ifndef wxUSE_WCHAR_T
168 #define wxUSE_WCHAR_T 1
169 #endif /* !defined(wxUSE_WCHAR_T) */
171 /* and we also do have wcslen() */
175 #endif /* wxHAVE_TCHAR_SUPPORT */
177 /* ---------------------------------------------------------------------------- */
178 /* define wxChar type */
179 /* ---------------------------------------------------------------------------- */
181 /* TODO: define wxCharInt to be equal to either int or wint_t? */
185 typedef signed char wxSChar
;
186 typedef unsigned char wxUChar
;
188 /* VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as */
189 /* signed/unsigned version of it which (a) makes sense to me (unlike */
190 /* char wchar_t is always unsigned) and (b) was how the previous */
191 /* definitions worked so keep it like this */
193 /* Sun's SunPro compiler supports the wchar_t type and wide character */
194 /* functions, but does not define __WCHAR_TYPE__. Define it here to */
195 /* allow unicode enabled builds. */
196 #if defined(__SUNPRO_CC) || defined(__SUNPRO_C)
197 #define __WCHAR_TYPE__ wxchar_t
200 /* GNU libc has __WCHAR_TYPE__ which requires special treatment, see */
202 #if !defined(__WCHAR_TYPE__) || \
203 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
205 typedef wchar_t wxChar
;
206 typedef wchar_t wxSChar
;
207 typedef wchar_t wxUChar
;
208 #else /* __WCHAR_TYPE__ and gcc < 2.96 */
209 /* VS: wxWidgets used to define wxChar as __WCHAR_TYPE__ here. However, */
210 /* this doesn't work with new GCC 3.x compilers because wchar_t is */
211 /* C++'s builtin type in the new standard. OTOH, old compilers (GCC */
212 /* 2.x) won't accept new definition of wx{S,U}Char, therefore we */
213 /* have to define wxChar conditionally depending on detected */
214 /* compiler & compiler version. */
215 /* with old definition of wxChar. */
216 typedef __WCHAR_TYPE__ wxChar
;
217 typedef __WCHAR_TYPE__ wxSChar
;
218 typedef __WCHAR_TYPE__ wxUChar
;
219 #endif /* __WCHAR_TYPE__ */
220 #endif /* ASCII/Unicode */
222 /* ---------------------------------------------------------------------------- */
223 /* define _T() and related macros */
224 /* ---------------------------------------------------------------------------- */
226 /* BSD systems define _T() to be something different in ctype.h, override it */
227 #if defined(__FreeBSD__) || defined(__DARWIN__)
232 /* could already be defined by tchar.h (it's quasi standard) */
237 /* use wxCONCAT_HELPER so that x could be expanded if it's a macro */
238 #define _T(x) wxCONCAT_HELPER(L, x)
239 #endif /* ASCII/Unicode */
240 #endif /* !defined(_T) */
242 /* although global macros with such names are normally bad, we want to have */
243 /* another name for _T() which should be used to avoid confusion between _T() */
244 /* and _() in wxWidgets sources */
247 /* a helper macro allowing to make another macro Unicode-friendly, see below */
248 #define wxAPPLY_T(x) _T(x)
250 /* Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs */
252 #define __TFILE__ wxAPPLY_T(__FILE__)
256 #define __TDATE__ wxAPPLY_T(__DATE__)
260 #define __TTIME__ wxAPPLY_T(__TIME__)
264 define wxFoo() function for each standard foo() function whose signature
265 (exceptionally including the return type) includes any mention of char:
266 wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
267 the same signature but with char replaced by wxChar which allows us to use
268 it in Unicode build as well
271 #ifdef wxHAVE_TCHAR_SUPPORT
274 #if defined(__WATCOMC__) && defined(UNICODE)
275 #define WXWCHAR_T_CAST(c) (wint_t)(c)
277 #define WXWCHAR_T_CAST(c) c
280 /* ctype.h functions */
281 #define wxIsalnum(c) _istalnum(WXWCHAR_T_CAST(c))
282 #define wxIsalpha(c) _istalpha(WXWCHAR_T_CAST(c))
283 #define wxIscntrl(c) _istcntrl(WXWCHAR_T_CAST(c))
284 #define wxIsdigit(c) _istdigit(WXWCHAR_T_CAST(c))
285 #define wxIsgraph(c) _istgraph(WXWCHAR_T_CAST(c))
286 #define wxIslower(c) _istlower(WXWCHAR_T_CAST(c))
287 #define wxIsprint(c) _istprint(WXWCHAR_T_CAST(c))
288 #define wxIspunct(c) _istpunct(WXWCHAR_T_CAST(c))
289 #define wxIsspace(c) _istspace(WXWCHAR_T_CAST(c))
290 #define wxIsupper(c) _istupper(WXWCHAR_T_CAST(c))
291 #define wxIsxdigit(c) _istxdigit(WXWCHAR_T_CAST(c))
294 There is a bug in VC6 C RTL: toxxx() functions dosn't do anything with
295 signed chars < 0, so "fix" it here.
297 #define wxTolower(c) _totlower((wxUChar)(c))
298 #define wxToupper(c) _totupper((wxUChar)(c))
300 /* locale.h functons */
301 #define wxSetlocale _tsetlocale
303 /* string.h functions */
304 #define wxStrcat _tcscat
305 #define wxStrchr _tcschr
306 #define wxStrcmp _tcscmp
307 #define wxStrcoll _tcscoll
308 #define wxStrcpy _tcscpy
309 #define wxStrcspn _tcscspn
310 #define wxStrdupW _wcsdup /* notice the 'W'! */
311 #define wxStrftime _tcsftime
312 #define wxStricmp _tcsicmp
313 #define wxStrnicmp _tcsnicmp
314 #define wxStrlen_ _tcslen /* used in wxStrlen inline function */
315 #define wxStrncat _tcsncat
316 #define wxStrncmp _tcsncmp
317 #define wxStrncpy _tcsncpy
318 #define wxStrpbrk _tcspbrk
319 #define wxStrrchr _tcsrchr
320 #define wxStrspn _tcsspn
321 #define wxStrstr _tcsstr
322 #define wxStrtod _tcstod
323 #define wxStrtol _tcstol
324 #define wxStrtoul _tcstoul
325 #define wxStrxfrm _tcsxfrm
327 /* stdio.h functions */
328 #define wxFgetc _fgettc
329 #define wxFgetchar _fgettchar
330 #define wxFgets _fgetts
331 #if wxUSE_UNICODE_MSLU
332 #define wxFopen wxMSLU__tfopen
334 #define wxFopen _tfopen
336 #define wxFputc _fputtc
337 #define wxFputchar _fputtchar
338 #define wxFprintf _ftprintf
339 #define wxFputs _fputts
340 #define wxFreopen _tfreopen
341 #define wxFscanf _ftscanf
342 #define wxGetc _gettc
343 #define wxGetchar _gettchar
344 #define wxGets _getts
345 #define wxPerror _tperror
346 #define wxPrintf _tprintf
347 #define wxPutc(c,f) _puttc(WXWCHAR_T_CAST(c),f)
348 #define wxPutchar _puttchar
349 #define wxPuts _putts
350 #define wxScanf _tscanf
353 /* Digital Mars adds count to _stprintf (C99) so prototype conversion see wxchar.cpp */
354 int wxSprintf (wchar_t * __RESTRICT s
, const wchar_t * __RESTRICT format
, ... ) ;
356 /* and there is a bug in D Mars tchar.h prior to 8.39.4n, so define as sprintf */
357 #define wxSprintf sprintf
360 #define wxSprintf _stprintf
363 #define wxSscanf _stscanf
364 #define wxTmpnam _ttmpnam
365 #define wxUngetc _tungetc
366 #define wxVfprintf _vftprintf
367 #define wxVprintf _vtprintf
368 #define wxVsscanf _vstscanf
369 #define wxVsprintf _vstprintf
371 /* special case: these functions are missing under Win9x with Unicows so we */
372 /* have to implement them ourselves */
373 #if wxUSE_UNICODE_MSLU
374 #define wxRemove wxMSLU__tremove
375 #define wxRename wxMSLU__trename
378 /* carefully: wxRemove() must return 0 on success while DeleteFile()
379 returns 0 on error, so don't just define one as the other */
380 int wxRemove(const wxChar
*path
);
382 #define wxRemove _tremove
383 #define wxRename _trename
387 /* stdlib.h functions */
390 /* #define wxAtof _tttof -- notice that there is no such thing (why?) */
391 /* there are no env vars at all under CE, so no _tgetenv neither */
393 /* can't define as inline function as this is a C file... */
394 #define wxGetenv(name) ((wxChar *)NULL)
396 #define wxGetenv _tgetenv
398 #define wxSystem _tsystem
400 /* time.h functions */
401 #define wxAsctime _tasctime
402 #define wxCtime _tctime
404 #define wxMbstowcs mbstowcs
405 #define wxWcstombs wcstombs
406 #else /* !TCHAR-aware compilers */
408 There are 2 unrelated problems with these functions under Mac:
409 a) Metrowerks MSL CRT implements them strictly in C99 sense and
410 doesn't support (very common) extension of allowing to call
411 mbstowcs(NULL, ...) which makes it pretty useless as you can't
412 know the size of the needed buffer
413 b) OS X <= 10.2 declares and even defined these functions but
414 doesn't really implement them -- they always return an error
416 So use our own replacements in both cases.
418 #if defined(__MWERKS__) && defined(__MSL__)
419 #define wxNEED_WX_MBSTOWCS
423 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2
424 #define wxNEED_WX_MBSTOWCS
428 #ifdef wxNEED_WX_MBSTOWCS
429 /* even though they are defined and "implemented", they are bad and just
430 stubs so we need our own - we need these even in ANSI builds!! */
431 WXDLLIMPEXP_BASE
size_t wxMbstowcs (wchar_t *, const char *, size_t);
432 WXDLLIMPEXP_BASE
size_t wxWcstombs (char *, const wchar_t *, size_t);
434 #define wxMbstowcs mbstowcs
435 #define wxWcstombs wcstombs
439 The system C library on Mac OS X 10.2 and below does not support
440 unicode: in other words all wide-character functions such as towupper et
441 al. do simply not exist so we need to provide our own in that context,
442 except for the wchar_t definition/typedef itself.
444 We need to do this for both project builder and CodeWarrior as
445 the latter uses the system C library in Mach builds for wide character
446 support, which as mentioned does not exist on 10.2 and below.
448 #if wxUSE_UNICODE && \
449 defined(__DARWIN__) && \
450 ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 )
451 /* we need everything! */
452 #define wxNEED_WX_STRING_H
453 #define wxNEED_WX_CTYPE_H
455 #define wxFgetchar(c) wxFgetc(c, stdin)
456 #define wxFputc wxPutc
457 #define wxFputchar(c) wxPutc(c, stdout)
458 #define wxGetc wxFgetc
459 #define wxGetchar(c) wxFgetc(c, stdin)
466 #define wxNEED_UNGETC
472 int wxFputs(const wxChar
*ch
, FILE *stream
);
473 int wxPuts(const wxChar
*ws
);
474 int wxPutc(wxChar ch
, FILE *stream
);
479 WXDLLIMPEXP_BASE
size_t wxStrlen_(const wxChar
*s
);
484 #define wxPutchar(wch) wxPutc(wch, stdout)
486 #define wxNEED_PRINTF_CONVERSION
487 #define wxNEED_WX_STDIO_H
488 #define wxNEED_WX_STDLIB_H
489 #define wxNEED_WX_TIME_H
494 /* this is probably glibc-specific */
495 #if defined(__WCHAR_TYPE__) && !defined(__MWERKS__)
496 /* ctype.h functions (wctype.h) */
497 #define wxIsalnum iswalnum
498 #define wxIsalpha iswalpha
499 #define wxIscntrl iswcntrl
500 #define wxIsdigit iswdigit
501 #define wxIsgraph iswgraph
502 #define wxIslower iswlower
503 #define wxIsprint iswprint
504 #define wxIspunct iswpunct
505 #define wxIsspace iswspace
506 #define wxIsupper iswupper
507 #define wxIsxdigit iswxdigit
509 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
510 /* /usr/include/wctype.h incorrectly declares translations */
511 /* tables which provokes tons of compile-time warnings -- try */
512 /* to correct this */
513 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
514 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
515 #else /* !glibc 2.0 */
516 #define wxTolower towlower
517 #define wxToupper towupper
518 #endif /* gcc/!gcc */
520 /* string.h functions (wchar.h) */
521 #define wxStrcat wcscat
522 #define wxStrchr wcschr
523 #define wxStrcmp wcscmp
524 #define wxStrcoll wcscoll
525 #define wxStrcpy wcscpy
526 #define wxStrcspn wcscspn
527 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
528 #define wxStrncat wcsncat
529 #define wxStrncmp wcsncmp
530 #define wxStrncpy wcsncpy
531 #define wxStrpbrk wcspbrk
532 #define wxStrrchr wcsrchr
533 #define wxStrspn wcsspn
534 #define wxStrstr wcsstr
535 #define wxStrtod wcstod
536 #define wxStrtol wcstol
537 #define wxStrtoul wcstoul
538 #define wxStrxfrm wcsxfrm
540 #define wxFgetc fgetwc
541 #define wxFgetchar fgetwchar
542 #define wxFgets fgetws
543 #define wxFputc fputwc
544 #define wxFputchar fputwchar
546 #define wxGetchar getwchar
548 #define wxUngetc ungetwc
551 #define wxFputs fputws
555 int wxFputs(const wxChar
*ch
, FILE *stream
);
563 int wxPutc(wxChar ch
, FILE *stream
);
567 #define wxPutchar wputchar
569 #define wxPutchar(wch) wxPutc(wch, stdout)
576 int wxPuts(const wxChar
*ws
);
579 /* we need %s to %ls conversion for printf and scanf etc */
580 #define wxNEED_PRINTF_CONVERSION
582 /* glibc doesn't have wide char equivalents of the other stuff so */
583 /* use our own versions */
584 #define wxNEED_WX_STDIO_H
585 #define wxNEED_WX_STDLIB_H
586 #define wxNEED_WX_TIME_H
587 #elif defined(__MWERKS__) && ( defined(__MSL__) || defined(__MACH__) )
588 /* ctype.h functions (wctype.h) */
589 #define wxIsalnum iswalnum
590 #define wxIsalpha iswalpha
591 #define wxIscntrl iswcntrl
592 #define wxIsdigit iswdigit
593 #define wxIsgraph iswgraph
594 #define wxIslower iswlower
595 #define wxIsprint iswprint
596 #define wxIspunct iswpunct
597 #define wxIsspace iswspace
598 #define wxIsupper iswupper
599 #define wxIsxdigit iswxdigit
600 #define wxTolower towlower
601 #define wxToupper towupper
603 /* string.h functions (wchar.h) */
604 #define wxStrcat wcscat
605 #define wxStrchr wcschr
606 #define wxStrcmp wcscmp
607 #define wxStrcoll wcscoll
608 #define wxStrcpy wcscpy
609 #define wxStrcspn wcscspn
610 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
611 #define wxStrncat wcsncat
612 #define wxStrncmp wcsncmp
613 #define wxStrncpy wcsncpy
614 #define wxStrpbrk wcspbrk
615 #define wxStrrchr wcsrchr
616 #define wxStrspn wcsspn
617 #define wxStrstr wcsstr
618 #define wxStrtod wcstod
619 #define wxStrtol wcstol
620 #define wxStrtoul wcstoul
621 #define wxStrxfrm wcsxfrm
623 #define wxFgetc fgetwc
624 #define wxFgetchar fgetwchar
625 #define wxFgets fgetws
626 #define wxFputc fputwc
627 #define wxFputchar fputwchar
629 #define wxGetchar getwchar
631 #define wxUngetc ungetwc
633 #define wxNEED_PRINTF_CONVERSION
636 #define wxPutchar putwchar
637 #define wxFputs fputws
639 /* stdio.h functions */
641 #define wxNEED_WX_STDIO_H
643 /* stdlib.h functions */
645 #define wxNEED_WX_STDLIB_H
650 #define wxGetenv(a) ((wxChar*)NULL)
651 #define wxSystem(a) ((int)NULL)
653 /* time.h functions */
654 #define wxAsctime wasciitime
655 #define wxCtime wctime
656 /* #define wxStrftime wcsftime */
658 #define wxNEED_WX_TIME_H
659 #else /* !metrowerks for apple */
660 #error "Please define wide character functions for your environment"
666 /* ctype.h functions */
667 #define wxIsalnum isalnum
668 #define wxIsalpha isalpha
669 #define wxIscntrl iscntrl
670 #define wxIsdigit isdigit
671 #define wxIsgraph isgraph
672 #define wxIslower islower
673 #define wxIsprint isprint
674 #define wxIspunct ispunct
675 #define wxIsspace isspace
676 #define wxIsupper isupper
677 #define wxIsxdigit isxdigit
678 #define wxTolower tolower
679 #define wxToupper toupper
681 /* locale.h functons */
682 #define wxSetlocale setlocale
684 /* string.h functions */
685 #define wxStrcat strcat
686 #define wxStrchr strchr
687 #define wxStrcmp strcmp
688 #define wxStrcoll strcoll
689 #define wxStrcpy strcpy
690 #define wxStrcspn strcspn
692 /* wxStricmp and wxStrnicmp are defined below */
693 #define wxStrlen_ strlen /* used in wxStrlen inline function */
694 #define wxStrncat strncat
695 #define wxStrncmp strncmp
696 #define wxStrncpy strncpy
697 #define wxStrpbrk strpbrk
698 #define wxStrrchr strrchr
699 #define wxStrspn strspn
700 #define wxStrstr strstr
701 #define wxStrtod strtod
703 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
705 #define wxStrtol strtol
706 #define wxStrtoul strtoul
707 #define wxStrxfrm strxfrm
709 /* stdio.h functions */
710 #define wxFopen fopen
711 #define wxFreopen freopen
712 #define wxRemove remove
713 #define wxRename rename
715 #define wxPerror perror
716 #define wxTmpnam tmpnam
718 #define wxFgetc fgetc
719 #define wxFgetchar fgetchar
720 #define wxFgets fgets
721 #define wxFputc fputc
722 #define wxFputs fputs
723 #define wxFputchar fputchar
724 #define wxFprintf fprintf
725 #define wxFscanf fscanf
727 #define wxGetchar getchar
729 #define wxPrintf printf
731 #define wxPutchar putchar
733 #define wxScanf scanf
734 #define wxSprintf sprintf
735 #define wxSscanf sscanf
736 #define wxUngetc ungetc
737 #define wxVfprintf vfprintf
738 #define wxVprintf vprintf
739 #define wxVsscanf vsscanf
740 #define wxVsprintf vsprintf
742 /* stdlib.h functions */
746 #define wxGetenv getenv
747 #define wxSystem system
749 /* time.h functions */
750 #define wxAsctime asctime
751 #define wxCtime ctime
752 #define wxStrftime strftime
753 #endif /* Unicode/ASCII */
754 #endif /* TCHAR-aware compilers/the others */
757 various special cases
760 /* define wxStricmp and wxStrnicmp for various compilers */
762 /* note that in Unicode mode we definitely are going to need our own version */
763 #if !defined(wxStricmp) && !wxUSE_UNICODE
764 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
765 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
766 defined(__EMX__) || defined(__DJGPP__)
767 #define wxStricmp stricmp
768 #define wxStrnicmp strnicmp
769 #elif defined(__WXPALMOS__)
770 /* FIXME: There is no equivalent to strnicmp in the Palm OS API. This
771 * quick hack should do until one can be written.
773 #define wxStricmp StrCaselessCompare
774 #define wxStrnicmp strnicmp
775 #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
776 (defined(__MWERKS__) && defined(__INTEL__))
777 #define wxStricmp _stricmp
778 #define wxStrnicmp _strnicmp
779 #elif defined(__UNIX__) || defined(__GNUWIN32__)
780 #define wxStricmp strcasecmp
781 #define wxStrnicmp strncasecmp
782 /* #else -- use wxWidgets implementation */
784 #endif /* !defined(wxStricmp) */
786 /* define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as */
787 /* it's used in wx/buffer.h -- and also might be used just below by wxStrlen() */
788 /* when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen) */
791 #define wxWcslen wcslen
793 WXDLLIMPEXP_BASE
size_t wxWcslen(const wchar_t *s
);
795 #endif /* wxUSE_WCHAR_T */
798 /* checks whether the passed in pointer is NULL and if the string is empty */
799 inline bool wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
801 /* safe version of strlen() (returns 0 if passed NULL pointer) */
802 inline size_t wxStrlen(const wxChar
*psz
) { return psz
? wxStrlen_(psz
) : 0; }
806 each of strdup() and wcsdup() may or may not be available but we need both
807 of them anyhow for wx/buffer.h so we define the missing one(s) in
808 wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
809 defined -- if this is somehow not the case in some situations, please
810 correct that and not the lines here
813 #define wxStrdup wxStrdupW
815 #define wxStrdup wxStrdupA
819 WXDLLIMPEXP_BASE
bool wxOKlibc(); /* for internal use */
822 /* printf() family saga */
825 For some systems [v]snprintf() exists in the system libraries but not in the
826 headers, so we need to declare it ourselves to be able to use it.
828 #if defined(HAVE_VSNPRINTF) && !defined(HAVE_VSNPRINTF_DECL)
834 int vsnprintf(char *str
, size_t size
, const char *format
, va_list ap
);
835 #endif /* !HAVE_VSNPRINTF_DECL */
837 #if defined(HAVE_SNPRINTF) && !defined(HAVE_SNPRINTF_DECL)
843 int snprintf(char *str
, size_t size
, const char *format
, ...);
844 #endif /* !HAVE_SNPRINTF_DECL */
846 /* Wrapper for vsnprintf if it's 3rd parameter is non-const. Note: the
847 * same isn't done for snprintf below, the builtin wxSnprintf_ is used
848 * instead since it's already a simple wrapper */
849 #if defined __cplusplus && defined HAVE_BROKEN_VSNPRINTF_DECL
850 inline int wx_fixed_vsnprintf(char *str
, size_t size
, const char *format
, va_list ap
)
852 return vsnprintf(str
, size
, (char*)format
, ap
);
857 MinGW MSVCRT has non-standard vswprintf() (for MSVC compatibility
858 presumably) and normally _vsnwprintf() is used instead
860 vswprintf() under (early versions of) OS X is buggy
862 #if defined(HAVE_VSWPRINTF) && (defined(__MINGW32__) || defined(__DARWIN__))
863 #undef HAVE_VSWPRINTF
866 #if wxUSE_PRINTF_POS_PARAMS
868 The systems where vsnprintf() supports positional parameters should
869 define the HAVE_UNIX98_PRINTF symbol.
871 On systems which don't (e.g. Windows) we are forced to use
872 our wxVsnprintf() implementation.
874 #if defined(HAVE_UNIX98_PRINTF)
876 #ifdef HAVE_VSWPRINTF
877 #define wxVsnprintf_ vswprintf
880 #ifdef HAVE_BROKEN_VSNPRINTF_DECL
881 #define wxVsnprintf_ wx_fixed_vsnprintf
883 #define wxVsnprintf_ vsnprintf
886 #else /* !HAVE_UNIX98_PRINTF */
888 The only compiler with positional parameters support under Windows
889 is VC++ 8.0 which provides a new xxprintf_p() functions family
891 #if defined(__VISUALC__) && __VISUALC__ >= 1400
893 #define wxVsnprintf_ _vswprintf_p
895 #define wxVsnprintf_ _vsprintf_p
898 #endif /* HAVE_UNIX98_PRINTF/!HAVE_UNIX98_PRINTF */
899 #else /* !wxUSE_PRINTF_POS_PARAMS */
901 We always want to define safe snprintf() function to be used instead of
902 sprintf(). Some compilers already have it (or rather vsnprintf() which
903 we really need...), otherwise we implement it using our own printf()
906 We define function with a trailing underscore here because the real one
907 is a wrapper around it as explained below
910 /* first deal with TCHAR-aware compilers which have _vsntprintf */
912 #if defined(__VISUALC__) || \
913 (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
914 #define wxVsnprintf_ _vsntprintf
915 #define wxSnprintf_ _sntprintf
919 /* if this didn't work, define it separately for Unicode and ANSI builds */
922 #if defined(HAVE__VSNWPRINTF)
923 #define wxVsnprintf_ _vsnwprintf
924 #elif defined(HAVE_VSWPRINTF)
925 #define wxVsnprintf_ vswprintf
926 #elif defined(__WATCOMC__)
927 #define wxVsnprintf_ _vsnwprintf
928 #define wxSnprintf_ _snwprintf
932 All versions of CodeWarrior supported by wxWidgets apparently
933 have both snprintf() and vsnprintf()
935 #if defined(HAVE_SNPRINTF) \
936 || defined(__MWERKS__) || defined(__WATCOMC__)
937 #ifndef HAVE_BROKEN_SNPRINTF_DECL
938 #define wxSnprintf_ snprintf
941 #if defined(HAVE_VSNPRINTF) \
942 || defined(__MWERKS__) || defined(__WATCOMC__)
943 #ifdef HAVE_BROKEN_VSNPRINTF_DECL
944 #define wxVsnprintf_ wx_fixed_vsnprintf
946 #define wxVsnprintf_ vsnprintf
949 #endif /* Unicode/ASCII */
950 #endif /* wxVsnprintf_ */
951 #endif /* wxUSE_PRINTF_POS_PARAMS/!wxUSE_PRINTF_POS_PARAMS */
954 /* no [v]snprintf(), cook our own */
956 wxSnprintf_(wxChar
*buf
, size_t len
, const wxChar
*format
, ...) ATTRIBUTE_PRINTF_3
;
960 wxVsnprintf_(wxChar
*buf
, size_t len
, const wxChar
*format
, va_list argptr
);
964 In Unicode mode we need to have all standard functions such as wprintf() and
965 so on but not all systems have them so use our own implementations in this
968 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
969 #define wxNEED_WPRINTF
973 More Unicode complications: although both ANSI C and C++ define a number of
974 wide character functions such as wprintf(), not all environments have them.
975 Worse, those which do have different behaviours: under Windows, %s format
976 specifier changes its meaning in Unicode build and expects a Unicode string
977 while under Unix/POSIX it still means an ASCII string even for wprintf() and
978 %ls has to be used for wide strings.
980 We choose to always emulate Windows behaviour as more useful for us so even
981 if we have wprintf() we still must wrap it in a non trivial wxPrintf().
985 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
987 we need to implement all wide character printf and scanf functions
988 either because we don't have them at all or because they don't have the
992 #include <stdio.h> /* for FILE */
994 int wxScanf( const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_1
;
995 int wxSscanf( const wxChar
*str
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
996 int wxFscanf( FILE *stream
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
997 int wxVsscanf( const wxChar
*str
, const wxChar
*format
, va_list ap
);
998 int wxPrintf( const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_1
;
999 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
1000 int wxFprintf( FILE *stream
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
1001 int wxVfprintf( FILE *stream
, const wxChar
*format
, va_list ap
);
1002 int wxVprintf( const wxChar
*format
, va_list ap
);
1003 int wxVsprintf( wxChar
*str
, const wxChar
*format
, va_list ap
);
1004 #endif /* wxNEED_PRINTF_CONVERSION */
1006 /* these 2 can be simply mapped to the versions with underscore at the end */
1007 /* if we don't have to do the conversion */
1009 However, if we don't have any vswprintf() at all we don't need to redefine
1010 anything as our own wxVsnprintf_() already behaves as needed.
1012 #if defined(wxNEED_PRINTF_CONVERSION) && defined(wxVsnprintf_)
1013 int wxSnprintf( wxChar
*str
, size_t size
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_3
;
1014 int wxVsnprintf( wxChar
*str
, size_t size
, const wxChar
*format
, va_list ap
);
1016 #define wxSnprintf wxSnprintf_
1017 #define wxVsnprintf wxVsnprintf_
1021 various functions which might not be available in libc and for which we
1022 provide our own replacements in wxchar.cpp
1025 /* ctype.h functions */
1027 /* RN: Used only under OSX <= 10.2 currently */
1028 #ifdef wxNEED_WX_CTYPE_H
1029 WXDLLIMPEXP_BASE
int wxIsalnum(wxChar ch
);
1030 WXDLLIMPEXP_BASE
int wxIsalpha(wxChar ch
);
1031 WXDLLIMPEXP_BASE
int wxIscntrl(wxChar ch
);
1032 WXDLLIMPEXP_BASE
int wxIsdigit(wxChar ch
);
1033 WXDLLIMPEXP_BASE
int wxIsgraph(wxChar ch
);
1034 WXDLLIMPEXP_BASE
int wxIslower(wxChar ch
);
1035 WXDLLIMPEXP_BASE
int wxIsprint(wxChar ch
);
1036 WXDLLIMPEXP_BASE
int wxIspunct(wxChar ch
);
1037 WXDLLIMPEXP_BASE
int wxIsspace(wxChar ch
);
1038 WXDLLIMPEXP_BASE
int wxIsupper(wxChar ch
);
1039 WXDLLIMPEXP_BASE
int wxIsxdigit(wxChar ch
);
1040 WXDLLIMPEXP_BASE
int wxTolower(wxChar ch
);
1041 WXDLLIMPEXP_BASE
int wxToupper(wxChar ch
);
1042 #endif /* wxNEED_WX_CTYPE_H */
1044 /* under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks */
1045 /* the file parsing -- this may be true for 5.0 as well, update #ifdef then */
1046 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
1048 #define wxIsspace(c) ((((unsigned)c) < 128) && isspace(c))
1052 a few compilers don't have the (non standard but common) isascii function,
1053 define it ourselves for them
1056 #if defined(__MWERKS__)
1057 #define wxNEED_ISASCII
1058 #elif defined(_WIN32_WCE)
1059 #if _WIN32_WCE <= 211
1060 #define wxNEED_ISASCII
1063 #endif /* isascii */
1065 #ifdef wxNEED_ISASCII
1066 inline int isascii(int c
) { return (unsigned)c
< 0x80; }
1070 #if _WIN32_WCE <= 211
1071 #define isspace(c) ((c) == _T(' ') || (c) == _T('\t'))
1073 #endif /* _WIN32_WCE */
1076 we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
1077 initial versions of this header -- now it is too late to remove it so
1078 although we fixed the function/macro name above, still provide the
1079 backwards-compatible synonym.
1081 #define wxIsctrl wxIscntrl
1083 /* string.h functions */
1085 #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)
1086 #define wxNEED_STRDUP
1087 #elif defined(__WXWINCE__)
1088 #if _WIN32_WCE <= 211
1089 #define wxNEED_STRDUP
1094 #ifdef wxNEED_STRDUP
1095 WXDLLIMPEXP_BASE
char *strdup(const char* s
);
1098 /* RN: Used only under OSX <= 10.2 currently
1099 The __cplusplus ifdefs are messy, but they are required to build
1100 the regex library, since c does not support function overloading
1102 #ifdef wxNEED_WX_STRING_H
1106 WXDLLIMPEXP_BASE wxChar
* wxStrcat(wxChar
*dest
, const wxChar
*src
);
1107 WXDLLIMPEXP_BASE
const wxChar
* wxStrchr(const wxChar
*s
, wxChar c
);
1108 WXDLLIMPEXP_BASE
int wxStrcmp(const wxChar
*s1
, const wxChar
*s2
);
1109 WXDLLIMPEXP_BASE
int wxStrcoll(const wxChar
*s1
, const wxChar
*s2
);
1110 WXDLLIMPEXP_BASE wxChar
* wxStrcpy(wxChar
*dest
, const wxChar
*src
);
1111 WXDLLIMPEXP_BASE
size_t wxStrcspn(const wxChar
*s
, const wxChar
*reject
);
1112 WXDLLIMPEXP_BASE wxChar
* wxStrncat(wxChar
*dest
, const wxChar
*src
, size_t n
);
1113 WXDLLIMPEXP_BASE
int wxStrncmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
);
1114 WXDLLIMPEXP_BASE wxChar
* wxStrncpy(wxChar
*dest
, const wxChar
*src
, size_t n
);
1115 WXDLLIMPEXP_BASE
const wxChar
* wxStrpbrk(const wxChar
*s
, const wxChar
*accept
);
1116 WXDLLIMPEXP_BASE
const wxChar
* wxStrrchr(const wxChar
*s
, wxChar c
);
1117 WXDLLIMPEXP_BASE
size_t wxStrspn(const wxChar
*s
, const wxChar
*accept
);
1118 WXDLLIMPEXP_BASE
const wxChar
* wxStrstr(const wxChar
*haystack
, const wxChar
*needle
);
1123 /* These functions use C++, so we can't c extern them */
1124 WXDLLIMPEXP_BASE
double wxStrtod(const wxChar
*nptr
, wxChar
**endptr
);
1125 WXDLLIMPEXP_BASE
long int wxStrtol(const wxChar
*nptr
, wxChar
**endptr
, int base
);
1126 WXDLLIMPEXP_BASE
unsigned long int wxStrtoul(const wxChar
*nptr
, wxChar
**endptr
, int base
);
1127 WXDLLIMPEXP_BASE
size_t wxStrxfrm(wxChar
*dest
, const wxChar
*src
, size_t n
);
1129 /* inlined versions */
1131 inline wxChar
* wxStrchr(wxChar
*s
, wxChar c
)
1132 { return (wxChar
*)wxStrchr((const wxChar
*)s
, c
); }
1133 inline wxChar
* wxStrpbrk(wxChar
*s
, const wxChar
*accept
)
1134 { return (wxChar
*)wxStrpbrk((const wxChar
*)s
, accept
); }
1135 inline wxChar
* wxStrrchr(wxChar
*s
, wxChar c
)
1136 { return (wxChar
*)wxStrrchr((const wxChar
*)s
, c
); }
1137 inline wxChar
*wxStrstr(wxChar
*haystack
, const wxChar
*needle
)
1138 { return (wxChar
*)wxStrstr((const wxChar
*)haystack
, needle
); }
1141 #endif /* wxNEED_WX_STRING_H */
1144 WXDLLIMPEXP_BASE
char *wxStrdupA(const char *psz
);
1148 WXDLLIMPEXP_BASE
wchar_t *wxStrdupW(const wchar_t *pwz
);
1152 WXDLLIMPEXP_BASE
int wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
1156 WXDLLIMPEXP_BASE
int wxStrnicmp(const wxChar
*psz1
, const wxChar
*psz2
, size_t len
);
1160 WXDLLIMPEXP_BASE wxChar
* wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
1165 class WXDLLIMPEXP_BASE wxWCharBuffer
;
1166 WXDLLIMPEXP_BASE wxWCharBuffer
wxSetlocale(int category
, const wxChar
*locale
);
1170 /* stdio.h functions */
1171 #ifdef wxNEED_WX_STDIO_H
1173 WXDLLIMPEXP_BASE
FILE * wxFopen(const wxChar
*path
, const wxChar
*mode
);
1174 WXDLLIMPEXP_BASE
FILE * wxFreopen(const wxChar
*path
, const wxChar
*mode
, FILE *stream
);
1175 WXDLLIMPEXP_BASE
int wxRemove(const wxChar
*path
);
1176 WXDLLIMPEXP_BASE
int wxRename(const wxChar
*oldpath
, const wxChar
*newpath
);
1178 /* *printf() family is handled separately */
1179 #endif /* wxNEED_WX_STDIO_H */
1182 /* stdlib.h functions */
1184 WXDLLIMPEXP_BASE
double wxAtof(const wxChar
*psz
);
1187 #ifdef wxNEED_WX_STDLIB_H
1188 WXDLLIMPEXP_BASE
int wxAtoi(const wxChar
*psz
);
1189 WXDLLIMPEXP_BASE
long wxAtol(const wxChar
*psz
);
1190 WXDLLIMPEXP_BASE wxChar
* wxGetenv(const wxChar
*name
);
1191 WXDLLIMPEXP_BASE
int wxSystem(const wxChar
*psz
);
1195 /* time.h functions */
1196 #ifdef wxNEED_WX_TIME_H
1197 #if defined(__MWERKS__) && defined(macintosh)
1200 /*silent gabby compilers*/
1202 WXDLLIMPEXP_BASE
size_t wxStrftime(wxChar
*s
, size_t max
,
1203 const wxChar
*fmt
, const struct tm
*tm
);
1204 #endif /* wxNEED_WX_TIME_H */
1208 WXDLLIMPEXP_BASE wxChar
*wxCtime(const time_t *timep
);
1212 /* missing functions in some WinCE versions */
1214 #if (_WIN32_WCE < 300)
1215 WXDLLIMPEXP_BASE
void *calloc( size_t num
, size_t size
);
1217 #endif /* _WIN32_WCE */
1219 /* multibyte to wide char conversion functions and macros */
1222 /* multibyte<->widechar conversion */
1223 WXDLLIMPEXP_BASE
size_t wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
1224 WXDLLIMPEXP_BASE
size_t wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
1227 #define wxMB2WX wxMB2WC
1228 #define wxWX2MB wxWC2MB
1229 #define wxWC2WX wxStrncpy
1230 #define wxWX2WC wxStrncpy
1232 #define wxMB2WX wxStrncpy
1233 #define wxWX2MB wxStrncpy
1234 #define wxWC2WX wxWC2MB
1235 #define wxWX2WC wxMB2WC
1237 #else /* !wxUSE_UNICODE */
1238 /* Why is this here?
1240 /* No wxUSE_WCHAR_T: we have to do something (JACS) */
1241 #define wxMB2WC wxStrncpy
1242 #define wxWC2MB wxStrncpy
1243 #define wxMB2WX wxStrncpy
1244 #define wxWX2MB wxStrncpy
1245 #define wxWC2WX wxWC2MB
1246 #define wxWX2WC wxMB2WC
1250 RN: The following are not normal versions of memcpy et al., rather
1251 these are either char or widechar versions depending on
1252 if unicode is used or not.
1258 // RN: We could do the usual tricky compiler detection here,
1259 // and use their variant (such as wmemchr, etc.). The problem
1260 // is that these functions are quite rare, even though they are
1261 // part of the current POSIX standard. In addition, most compilers
1262 // (including even MSC) inline them just like we do right in their
1266 #include <string.h> //for mem funcs
1268 //implement our own wmem variants
1269 inline wxChar
* wxTmemchr(const wxChar
* s
, wxChar c
, size_t l
)
1271 for(;l
&& *s
!= c
;--l
, ++s
) {}
1278 inline int wxTmemcmp(const wxChar
* sz1
, const wxChar
* sz2
, size_t len
)
1280 for(; *sz1
== *sz2
&& len
; --len
, ++sz1
, ++sz2
) {}
1283 return *sz1
< *sz2
? -1 : *sz1
> *sz2
;
1288 inline wxChar
* wxTmemcpy(wxChar
* szOut
, const wxChar
* szIn
, size_t len
)
1290 return (wxChar
*) memcpy(szOut
, szIn
, len
* sizeof(wxChar
));
1293 inline wxChar
* wxTmemmove(wxChar
* szOut
, const wxChar
* szIn
, size_t len
)
1295 return (wxChar
*) memmove(szOut
, szIn
, len
* sizeof(wxChar
));
1298 inline wxChar
* wxTmemset(wxChar
* szOut
, const wxChar cIn
, size_t len
)
1300 wxChar
* szRet
= szOut
;
1308 #else /* !wxUSE_UNICODE */
1309 # define wxTmemchr memchr
1310 # define wxTmemcmp memcmp
1311 # define wxTmemcpy memcpy
1312 # define wxTmemmove memmove
1313 # define wxTmemset memset
1314 #endif /* wxUSE_UNICODE/!wxUSE_UNICODE */
1316 #endif /*__cplusplus*/
1319 #endif /* _WX_WXCHAR_H_ */