3 * Purpose: Type-safe ANSI and Unicode builds compatible wrappers for
5 * Author: Joel Farley, Ove Kåven
6 * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee
9 * Copyright: (c) 1998-2006 wxWidgets dev team
10 * Licence: wxWindows licence
13 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
18 #include "wx/chartype.h"
21 #include "wx/strvararg.h"
23 /* make the file compile without doing anything in C code: */
24 #define WX_DEFINE_VARARG_FUNC(rettype, name, impl)
27 #include <stdio.h> /* we use FILE below */
29 #if defined(HAVE_STRTOK_R) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
30 char *strtok_r(char *, const char *, char **);
35 Standard headers we need here.
37 NB: don't include any wxWidgets headers here because almost all of them include
41 /* Required for wxPrintf() etc */
44 /* Almost all compiler have strdup(), but not quite all: CodeWarrior under Mac */
45 /* and VC++ for Windows CE don't provide it */
46 #if defined(__VISUALC__) && __VISUALC__ >= 1400
47 #define wxStrdupA _strdup
48 #elif !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
49 /* use #define, not inline wrapper, as it is tested with #ifndef below */
50 #define wxStrdupA strdup
53 #if defined(__MWERKS__)
54 /* Metrowerks only has wide char support for OS X >= 10.3 */
55 #if !defined(__DARWIN__) || \
56 (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)
57 #define wxHAVE_MWERKS_UNICODE
60 #ifdef wxHAVE_MWERKS_UNICODE
61 #define HAVE_WPRINTF 1
62 #define HAVE_WCSRTOMBS 1
63 #define HAVE_VSWPRINTF 1
65 #endif /* __MWERKS__ */
67 #ifdef wxHAVE_TCHAR_SUPPORT
68 /* we surely have wchar_t if we have TCHAR have wcslen() */
72 #endif /* wxHAVE_TCHAR_SUPPORT */
75 define wxFoo() function for each standard foo() function whose signature
76 (exceptionally including the return type) includes any mention of char:
77 wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
78 the same signature but with char replaced by wxChar which allows us to
79 use it in Unicode build as well
82 #ifdef wxHAVE_TCHAR_SUPPORT
85 #if defined(__WATCOMC__) && defined(UNICODE)
86 #define WXWCHAR_T_CAST(c) (wint_t)(c)
88 #define WXWCHAR_T_CAST(c) c
91 /* ctype.h functions */
92 #define wxIsalnum(c) _istalnum(WXWCHAR_T_CAST(c))
93 #define wxIsalpha(c) _istalpha(WXWCHAR_T_CAST(c))
94 #define wxIscntrl(c) _istcntrl(WXWCHAR_T_CAST(c))
95 #define wxIsdigit(c) _istdigit(WXWCHAR_T_CAST(c))
96 #define wxIsgraph(c) _istgraph(WXWCHAR_T_CAST(c))
97 #define wxIslower(c) _istlower(WXWCHAR_T_CAST(c))
98 #define wxIsprint(c) _istprint(WXWCHAR_T_CAST(c))
99 #define wxIspunct(c) _istpunct(WXWCHAR_T_CAST(c))
100 #define wxIsspace(c) _istspace(WXWCHAR_T_CAST(c))
101 #define wxIsupper(c) _istupper(WXWCHAR_T_CAST(c))
102 #define wxIsxdigit(c) _istxdigit(WXWCHAR_T_CAST(c))
105 There is a bug in VC6 C RTL: toxxx() functions dosn't do anything with
106 signed chars < 0, so "fix" it here.
108 #define wxTolower(c) _totlower((wxUChar)(wxChar)(c))
109 #define wxToupper(c) _totupper((wxUChar)(wxChar)(c))
111 /* locale.h functons */
112 #define wxSetlocale _tsetlocale
114 /* string.h functions */
115 #define wxStrcat _tcscat
116 #define wxStrchr _tcschr
117 #define wxStrcmp _tcscmp
118 #define wxStrcoll _tcscoll
119 #define wxStrcpy _tcscpy
120 #define wxStrcspn _tcscspn
121 #define wxStrdupW _wcsdup /* notice the 'W'! */
122 #define wxStrftime _tcsftime
123 #define wxStricmp _tcsicmp
124 #define wxStrnicmp _tcsnicmp
125 #define wxStrlen_ _tcslen /* used in wxStrlen inline function */
126 #define wxStrncat _tcsncat
127 #define wxStrncmp _tcsncmp
128 #define wxStrncpy _tcsncpy
129 #define wxStrpbrk _tcspbrk
130 #define wxStrrchr _tcsrchr
131 #define wxStrspn _tcsspn
132 #define wxStrstr _tcsstr
133 #define wxStrtod _tcstod
134 #define wxStrtol _tcstol
135 #define wxStrtoul _tcstoul
137 #if __VISUALC__ >= 1300 && !defined(__WXWINCE__)
138 #define wxStrtoll _tcstoi64
139 #define wxStrtoull _tcstoui64
142 #define wxStrxfrm _tcsxfrm
144 /* stdio.h functions */
145 #define wxFgetc _fgettc
146 #define wxFgetchar _fgettchar
147 #define wxFgets _fgetts
148 #if wxUSE_UNICODE_MSLU
149 WXDLLIMPEXP_BASE
FILE * wxMSLU__tfopen(const wxChar
*name
, const wxChar
*mode
);
151 #define wxFopen wxMSLU__tfopen
153 #define wxFopen _tfopen
155 #define wxFputc _fputtc
156 #define wxFputchar _fputtchar
157 WX_DEFINE_VARARG_FUNC(int, wxFprintf
, _ftprintf
)
158 #define wxFputs _fputts
159 #define wxFreopen _tfreopen
160 #define wxFscanf _ftscanf
161 #define wxGetc _gettc
162 #define wxGetchar _gettchar
163 #define wxGets _getts
164 #define wxPerror _tperror
165 WX_DEFINE_VARARG_FUNC(int, wxPrintf
, _tprintf
)
166 #define wxPutc(c,f) _puttc(WXWCHAR_T_CAST(c),f)
167 #define wxPutchar _puttchar
168 #define wxPuts _putts
169 #define wxScanf _tscanf
172 /* Digital Mars adds count to _stprintf (C99) so prototype conversion see wxchar.cpp */
173 int wxDoSprintf (wchar_t * __RESTRICT s
, const wchar_t * __RESTRICT format
, ... ) ;
174 WX_DEFINE_VARARG_FUNC(int, wxSprintf
, wxDoSprintf
)
176 /* and there is a bug in D Mars tchar.h prior to 8.39.4n, so define as sprintf */
177 WX_DEFINE_VARARG_FUNC(int, wxSprintf
, sprintf
)
180 WX_DEFINE_VARARG_FUNC(int, wxSprintf
, _stprintf
)
183 #define wxSscanf _stscanf
184 #define wxTmpnam _ttmpnam
185 #define wxUngetc _tungetc
186 #define wxVfprintf _vftprintf
187 #define wxVprintf _vtprintf
188 #define wxVsscanf _vstscanf
189 #define wxVsprintf _vstprintf
191 /* special case: these functions are missing under Win9x with Unicows so we */
192 /* have to implement them ourselves */
193 #if wxUSE_UNICODE_MSLU
194 WXDLLIMPEXP_BASE
int wxMSLU__trename(const wxChar
*oldname
, const wxChar
*newname
);
195 WXDLLIMPEXP_BASE
int wxMSLU__tremove(const wxChar
*name
);
197 #define wxRemove wxMSLU__tremove
198 #define wxRename wxMSLU__trename
201 /* carefully: wxRemove() must return 0 on success while DeleteFile()
202 returns 0 on error, so don't just define one as the other */
203 int wxRemove(const wxChar
*path
);
205 #define wxRemove _tremove
206 #define wxRename _trename
210 /* stdlib.h functions */
213 /* #define wxAtof _tttof -- notice that there is no such thing (why?) */
214 /* there are no env vars at all under CE, so no _tgetenv neither */
216 /* can't define as inline function as this is a C file... */
217 #define wxGetenv(name) ((wxChar *)NULL)
219 #define wxGetenv _tgetenv
221 #define wxSystem _tsystem
223 /* time.h functions */
224 #define wxAsctime _tasctime
225 #define wxCtime _tctime
227 #define wxMbstowcs mbstowcs
228 #define wxWcstombs wcstombs
229 #else /* !TCHAR-aware compilers */
231 There are 2 unrelated problems with these functions under Mac:
232 a) Metrowerks MSL CRT implements them strictly in C99 sense and
233 doesn't support (very common) extension of allowing to call
234 mbstowcs(NULL, ...) which makes it pretty useless as you can't
235 know the size of the needed buffer
236 b) OS X <= 10.2 declares and even defined these functions but
237 doesn't really implement them -- they always return an error
239 So use our own replacements in both cases.
241 #if defined(__MWERKS__) && defined(__MSL__)
242 #define wxNEED_WX_MBSTOWCS
246 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2
247 #define wxNEED_WX_MBSTOWCS
251 #ifdef wxNEED_WX_MBSTOWCS
252 /* even though they are defined and "implemented", they are bad and just
253 stubs so we need our own - we need these even in ANSI builds!! */
254 WXDLLIMPEXP_BASE
size_t wxMbstowcs (wchar_t *, const char *, size_t);
255 WXDLLIMPEXP_BASE
size_t wxWcstombs (char *, const wchar_t *, size_t);
257 #define wxMbstowcs mbstowcs
258 #define wxWcstombs wcstombs
262 The system C library on Mac OS X 10.2 and below does not support
263 unicode: in other words all wide-character functions such as towupper et
264 al. do simply not exist so we need to provide our own in that context,
265 except for the wchar_t definition/typedef itself.
267 We need to do this for both project builder and CodeWarrior as
268 the latter uses the system C library in Mach builds for wide character
269 support, which as mentioned does not exist on 10.2 and below.
271 #if wxUSE_UNICODE && \
272 defined(__DARWIN__) && \
273 ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 )
274 /* we need everything! */
275 #define wxNEED_WX_STRING_H
276 #define wxNEED_WX_CTYPE_H
278 #define wxFgetchar(c) wxFgetc(c, stdin)
279 #define wxFputc wxPutc
280 #define wxFputchar(c) wxPutc(c, stdout)
281 #define wxGetc wxFgetc
282 #define wxGetchar(c) wxFgetc(c, stdin)
289 #define wxNEED_UNGETC
295 int wxFputs(const wxChar
*ch
, FILE *stream
);
296 int wxPuts(const wxChar
*ws
);
297 int wxPutc(wxChar ch
, FILE *stream
);
302 WXDLLIMPEXP_BASE
size_t wxStrlen_(const wxChar
*s
);
307 #define wxPutchar(wch) wxPutc(wch, stdout)
309 #define wxNEED_PRINTF_CONVERSION
310 #define wxNEED_WX_STDIO_H
311 #define wxNEED_WX_STDLIB_H
312 #define wxNEED_WX_TIME_H
317 /* this is probably glibc-specific */
318 #if defined(__WCHAR_TYPE__) && !defined(__MWERKS__)
319 /* ctype.h functions (wctype.h) */
320 #define wxIsalnum iswalnum
321 #define wxIsalpha iswalpha
322 #define wxIscntrl iswcntrl
323 #define wxIsdigit iswdigit
324 #define wxIsgraph iswgraph
325 #define wxIslower iswlower
326 #define wxIsprint iswprint
327 #define wxIspunct iswpunct
328 #define wxIsspace iswspace
329 #define wxIsupper iswupper
330 #define wxIsxdigit iswxdigit
332 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
333 /* /usr/include/wctype.h incorrectly declares translations */
334 /* tables which provokes tons of compile-time warnings -- try */
335 /* to correct this */
336 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
337 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
338 #else /* !glibc 2.0 */
339 #define wxTolower towlower
340 #define wxToupper towupper
341 #endif /* gcc/!gcc */
343 /* string.h functions (wchar.h) */
344 #define wxStrcat wcscat
345 #define wxStrchr wcschr
346 #define wxStrcmp wcscmp
347 #define wxStrcoll wcscoll
348 #define wxStrcpy wcscpy
349 #define wxStrcspn wcscspn
350 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
351 #define wxStrncat wcsncat
352 #define wxStrncmp wcsncmp
353 #define wxStrncpy wcsncpy
354 #define wxStrpbrk wcspbrk
355 #define wxStrrchr wcsrchr
356 #define wxStrspn wcsspn
357 #define wxStrstr wcsstr
358 #define wxStrtod wcstod
359 #define wxStrtol wcstol
360 #define wxStrtoul wcstoul
362 /* assume that we have wcstoull(), which is also C99, too */
363 #define wxStrtoll wcstoll
364 #define wxStrtoull wcstoull
365 #endif /* HAVE_WCSTOULL */
366 #define wxStrxfrm wcsxfrm
368 #define wxFgetc fgetwc
369 #define wxFgetchar fgetwchar
370 #define wxFgets fgetws
371 #define wxFputc fputwc
372 #define wxFputchar fputwchar
374 #define wxGetchar getwchar
376 #define wxUngetc ungetwc
379 #define wxFputs fputws
383 int wxFputs(const wxChar
*ch
, FILE *stream
);
391 int wxPutc(wxChar ch
, FILE *stream
);
395 #define wxPutchar wputchar
397 #define wxPutchar(wch) wxPutc(wch, stdout)
404 int wxPuts(const wxChar
*ws
);
407 /* we need %s to %ls conversion for printf and scanf etc */
408 #define wxNEED_PRINTF_CONVERSION
410 /* glibc doesn't have wide char equivalents of the other stuff so */
411 /* use our own versions */
412 #define wxNEED_WX_STDIO_H
413 #define wxNEED_WX_STDLIB_H
414 #define wxNEED_WX_TIME_H
415 #elif defined(__MWERKS__) && ( defined(__MSL__) || defined(__MACH__) )
416 /* ctype.h functions (wctype.h) */
417 #define wxIsalnum iswalnum
418 #define wxIsalpha iswalpha
419 #define wxIscntrl iswcntrl
420 #define wxIsdigit iswdigit
421 #define wxIsgraph iswgraph
422 #define wxIslower iswlower
423 #define wxIsprint iswprint
424 #define wxIspunct iswpunct
425 #define wxIsspace iswspace
426 #define wxIsupper iswupper
427 #define wxIsxdigit iswxdigit
428 #define wxTolower towlower
429 #define wxToupper towupper
431 /* string.h functions (wchar.h) */
432 #define wxStrcat wcscat
433 #define wxStrchr wcschr
434 #define wxStrcmp wcscmp
435 #define wxStrcoll wcscoll
436 #define wxStrcpy wcscpy
437 #define wxStrcspn wcscspn
438 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
439 #define wxStrncat wcsncat
440 #define wxStrncmp wcsncmp
441 #define wxStrncpy wcsncpy
442 #define wxStrpbrk wcspbrk
443 #define wxStrrchr wcsrchr
444 #define wxStrspn wcsspn
445 #define wxStrstr wcsstr
446 #define wxStrtod wcstod
447 #define wxStrtol wcstol
448 #define wxStrtoul wcstoul
449 #define wxStrxfrm wcsxfrm
451 #define wxFgetc fgetwc
452 #define wxFgetchar fgetwchar
453 #define wxFgets fgetws
454 #define wxFputc fputwc
455 #define wxFputchar fputwchar
457 #define wxGetchar getwchar
459 #define wxUngetc ungetwc
461 #define wxNEED_PRINTF_CONVERSION
464 #define wxPutchar putwchar
465 #define wxFputs fputws
467 /* stdio.h functions */
469 #define wxNEED_WX_STDIO_H
471 /* stdlib.h functions */
473 #define wxNEED_WX_STDLIB_H
478 #define wxGetenv(a) ((wxChar*)NULL)
479 #define wxSystem(a) ((int)NULL)
481 /* time.h functions */
482 #define wxAsctime wasciitime
483 #define wxCtime wctime
484 /* #define wxStrftime wcsftime */
486 #define wxNEED_WX_TIME_H
487 #else /* !metrowerks for apple */
488 #error "Please define wide character functions for your environment"
494 /* ctype.h functions */
495 #define wxIsalnum isalnum
496 #define wxIsalpha isalpha
497 #define wxIscntrl iscntrl
498 #define wxIsdigit isdigit
499 #define wxIsgraph isgraph
500 #define wxIslower islower
501 #define wxIsprint isprint
502 #define wxIspunct ispunct
503 #define wxIsspace isspace
504 #define wxIsupper isupper
505 #define wxIsxdigit isxdigit
506 #define wxTolower tolower
507 #define wxToupper toupper
509 /* locale.h functons */
510 #define wxSetlocale setlocale
512 /* string.h functions */
513 #define wxStrcat strcat
514 #define wxStrchr strchr
515 #define wxStrcmp strcmp
516 #define wxStrcoll strcoll
517 #define wxStrcpy strcpy
518 #define wxStrcspn strcspn
520 /* wxStricmp and wxStrnicmp are defined below */
521 #define wxStrlen_ strlen /* used in wxStrlen inline function */
522 #define wxStrncat strncat
523 #define wxStrncmp strncmp
524 #define wxStrncpy strncpy
525 #define wxStrpbrk strpbrk
526 #define wxStrrchr strrchr
527 #define wxStrspn strspn
528 #define wxStrstr strstr
529 #define wxStrtod strtod
531 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
533 #define wxStrtol strtol
534 #define wxStrtoul strtoul
536 /* assume that we have wcstoull(), which is also C99, too */
537 #define wxStrtoll strtoll
538 #define wxStrtoull strtoull
539 #endif /* HAVE_WCSTOULL */
540 #define wxStrxfrm strxfrm
542 /* stdio.h functions */
543 #define wxFopen fopen
544 #define wxFreopen freopen
545 #define wxRemove remove
546 #define wxRename rename
548 #define wxPerror perror
549 #define wxTmpnam tmpnam
551 #define wxFgetc fgetc
552 #define wxFgetchar fgetchar
553 #define wxFgets fgets
554 #define wxFputc fputc
555 #define wxFputs fputs
556 #define wxFputchar fputchar
557 WX_DEFINE_VARARG_FUNC(int, wxFprintf
, fprintf
)
558 #define wxFscanf fscanf
560 #define wxGetchar getchar
562 WX_DEFINE_VARARG_FUNC(int, wxPrintf
, printf
)
564 #define wxPutchar putchar
566 #define wxScanf scanf
567 WX_DEFINE_VARARG_FUNC(int, wxSprintf
, sprintf
)
568 #define wxSscanf sscanf
569 #define wxUngetc ungetc
570 #define wxVfprintf vfprintf
571 #define wxVprintf vprintf
572 #define wxVsscanf vsscanf
573 #define wxVsprintf vsprintf
575 /* stdlib.h functions */
579 #define wxGetenv getenv
580 #define wxSystem system
582 /* time.h functions */
583 #define wxAsctime asctime
584 #define wxCtime ctime
585 #define wxStrftime strftime
586 #endif /* Unicode/ASCII */
587 #endif /* TCHAR-aware compilers/the others */
590 various special cases
593 /* define wxStricmp and wxStrnicmp for various compilers */
595 /* note that in Unicode mode we definitely are going to need our own version */
596 #if !defined(wxStricmp) && !wxUSE_UNICODE
597 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
598 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
599 defined(__EMX__) || defined(__DJGPP__)
600 #define wxStricmp stricmp
601 #define wxStrnicmp strnicmp
602 #elif defined(__WXPALMOS__)
603 /* FIXME: There is no equivalent to strnicmp in the Palm OS API. This
604 * quick hack should do until one can be written.
606 #define wxStricmp StrCaselessCompare
607 #define wxStrnicmp strnicmp
608 #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
609 (defined(__MWERKS__) && defined(__INTEL__))
610 #define wxStricmp _stricmp
611 #define wxStrnicmp _strnicmp
612 #elif defined(__UNIX__) || defined(__GNUWIN32__)
613 #define wxStricmp strcasecmp
614 #define wxStrnicmp strncasecmp
615 /* #else -- use wxWidgets implementation */
617 #endif /* !defined(wxStricmp) */
619 /* define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as */
620 /* it's used in wx/buffer.h -- and also might be used just below by wxStrlen() */
621 /* when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen) */
624 #define wxWcslen wcslen
626 WXDLLIMPEXP_BASE
size_t wxWcslen(const wchar_t *s
);
628 #endif /* wxUSE_WCHAR_T */
631 /* checks whether the passed in pointer is NULL and if the string is empty */
632 inline bool wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
634 /* safe version of strlen() (returns 0 if passed NULL pointer) */
635 inline size_t wxStrlen(const wxChar
*psz
) { return psz
? wxStrlen_(psz
) : 0; }
639 each of strdup() and wcsdup() may or may not be available but we need both
640 of them anyhow for wx/buffer.h so we define the missing one(s) in
641 wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
642 defined -- if this is somehow not the case in some situations, please
643 correct that and not the lines here
646 #define wxStrdup wxStrdupW
648 #define wxStrdup wxStrdupA
652 WXDLLIMPEXP_BASE
bool wxOKlibc(); /* for internal use */
655 /* printf() family saga */
658 For some systems [v]snprintf() exists in the system libraries but not in the
659 headers, so we need to declare it ourselves to be able to use it.
661 #if defined(HAVE_VSNPRINTF) && !defined(HAVE_VSNPRINTF_DECL)
667 int vsnprintf(char *str
, size_t size
, const char *format
, va_list ap
);
668 #endif /* !HAVE_VSNPRINTF_DECL */
670 #if defined(HAVE_SNPRINTF) && !defined(HAVE_SNPRINTF_DECL)
676 WXDLLIMPEXP_BASE
int snprintf(char *str
, size_t size
, const char *format
, ...);
677 #endif /* !HAVE_SNPRINTF_DECL */
679 /* Wrapper for vsnprintf if it's 3rd parameter is non-const. Note: the
680 * same isn't done for snprintf below, the builtin wxSnprintf_ is used
681 * instead since it's already a simple wrapper */
682 #if defined __cplusplus && defined HAVE_BROKEN_VSNPRINTF_DECL
683 inline int wx_fixed_vsnprintf(char *str
, size_t size
, const char *format
, va_list ap
)
685 return vsnprintf(str
, size
, (char*)format
, ap
);
690 MinGW MSVCRT has non-standard vswprintf() (for MSVC compatibility
691 presumably) and normally _vsnwprintf() is used instead
693 #if defined(HAVE_VSWPRINTF) && defined(__MINGW32__)
694 #undef HAVE_VSWPRINTF
697 #if wxUSE_PRINTF_POS_PARAMS
699 The systems where vsnprintf() supports positional parameters should
700 define the HAVE_UNIX98_PRINTF symbol.
702 On systems which don't (e.g. Windows) we are forced to use
703 our wxVsnprintf() implementation.
705 #if defined(HAVE_UNIX98_PRINTF)
707 #ifdef HAVE_VSWPRINTF
708 #define wxVsnprintf_ vswprintf
711 #ifdef HAVE_BROKEN_VSNPRINTF_DECL
712 #define wxVsnprintf_ wx_fixed_vsnprintf
714 #define wxVsnprintf_ vsnprintf
717 #else /* !HAVE_UNIX98_PRINTF */
719 The only compiler with positional parameters support under Windows
720 is VC++ 8.0 which provides a new xxprintf_p() functions family.
721 The 2003 PSDK includes a slightly earlier version of VC8 than the
722 main release and does not have the printf_p functions.
724 #if defined _MSC_FULL_VER && _MSC_FULL_VER >= 140050727 && !defined __WXWINCE__
726 #define wxVsnprintf_ _vswprintf_p
728 #define wxVsnprintf_ _vsprintf_p
731 #endif /* HAVE_UNIX98_PRINTF/!HAVE_UNIX98_PRINTF */
732 #else /* !wxUSE_PRINTF_POS_PARAMS */
734 We always want to define safe snprintf() function to be used instead of
735 sprintf(). Some compilers already have it (or rather vsnprintf() which
736 we really need...), otherwise we implement it using our own printf()
739 We define function with a trailing underscore here because the real one
740 is a wrapper around it as explained below
743 /* first deal with TCHAR-aware compilers which have _vsntprintf */
745 #if defined(__VISUALC__) || \
746 (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
747 #define wxSnprintf_ _sntprintf
748 #define wxVsnprintf_ _vsntprintf
749 WX_DEFINE_VARARG_FUNC(int, wxSnprintf_
, _sntprintf
)
753 /* if this didn't work, define it separately for Unicode and ANSI builds */
756 #if defined(HAVE__VSNWPRINTF)
757 #define wxVsnprintf_ _vsnwprintf
758 #elif defined(HAVE_VSWPRINTF)
759 #define wxVsnprintf_ vswprintf
760 #elif defined(__WATCOMC__)
761 #define wxVsnprintf_ _vsnwprintf
762 WX_DEFINE_VARARG_FUNC(int, wxSnprintf_
, _snwprintf
)
766 All versions of CodeWarrior supported by wxWidgets apparently
767 have both snprintf() and vsnprintf()
769 #if defined(HAVE_SNPRINTF) \
770 || defined(__MWERKS__) || defined(__WATCOMC__)
771 #ifndef HAVE_BROKEN_SNPRINTF_DECL
772 WX_DEFINE_VARARG_FUNC(int, wxSnprintf_
, snprintf
)
775 #if defined(HAVE_VSNPRINTF) \
776 || defined(__MWERKS__) || defined(__WATCOMC__)
777 #ifdef HAVE_BROKEN_VSNPRINTF_DECL
778 #define wxVsnprintf_ wx_fixed_vsnprintf
780 #define wxVsnprintf_ vsnprintf
783 #endif /* Unicode/ASCII */
784 #endif /* wxVsnprintf_ */
785 #endif /* wxUSE_PRINTF_POS_PARAMS/!wxUSE_PRINTF_POS_PARAMS */
788 /* no snprintf(), cook our own */
790 wxDoSnprintf_(wxChar
*buf
, size_t len
,
791 const wxChar
*format
, ...) ATTRIBUTE_PRINTF_3
;
792 WX_DEFINE_VARARG_FUNC(int, wxSnprintf_
, wxDoSnprintf_
)
795 /* no (suitable) vsnprintf(), cook our own */
797 wxVsnprintf_(wxChar
*buf
, size_t len
,
798 const wxChar
*format
, va_list argptr
);
800 #define wxUSE_WXVSNPRINTF 1
802 #define wxUSE_WXVSNPRINTF 0
806 /* supply strtoll and strtoull, if needed */
807 WXDLLIMPEXP_BASE wxLongLong_t
wxStrtoll(const wxChar
* nptr
, wxChar
** endptr
, int base
);
808 WXDLLIMPEXP_BASE wxULongLong_t
wxStrtoull(const wxChar
* nptr
, wxChar
** endptr
, int base
);
811 #define wxHAS_STRTOLL
814 In Unicode mode we need to have all standard functions such as wprintf() and
815 so on but not all systems have them so use our own implementations in this
818 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
819 #define wxNEED_WPRINTF
823 More Unicode complications: although both ANSI C and C++ define a number of
824 wide character functions such as wprintf(), not all environments have them.
825 Worse, those which do have different behaviours: under Windows, %s format
826 specifier changes its meaning in Unicode build and expects a Unicode string
827 while under Unix/POSIX it still means an ASCII string even for wprintf() and
828 %ls has to be used for wide strings.
830 We choose to always emulate Windows behaviour as more useful for us so even
831 if we have wprintf() we still must wrap it in a non trivial wxPrintf().
835 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
837 we need to implement all wide character printf and scanf functions
838 either because we don't have them at all or because they don't have the
841 WX_DEFINE_VARARG_FUNC(int, wxScanf
, wxDoScanf
)
842 int wxDoScanf( const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_1
;
844 WX_DEFINE_VARARG_FUNC(int, wxSscanf
, wxDoSscanf
)
845 int wxDoSscanf( const wxChar
*str
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
847 WX_DEFINE_VARARG_FUNC(int, wxFscanf
, wxDoFscanf
)
848 int wxDoFscanf( FILE *stream
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
850 WX_DEFINE_VARARG_FUNC(int, wxPrintf
, wxDoPrintf
)
851 int wxDoPrintf( const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_1
;
853 WX_DEFINE_VARARG_FUNC(int, wxSprintf
, wxDoSprintf
)
854 int wxDoSprintf( wxChar
*str
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
856 WX_DEFINE_VARARG_FUNC(int, wxFprintf
, wxDoFprintf
)
857 int wxDoFprintf( FILE *stream
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
859 int wxVsscanf( const wxChar
*str
, const wxChar
*format
, va_list ap
);
860 int wxVfprintf( FILE *stream
, const wxChar
*format
, va_list ap
);
861 int wxVprintf( const wxChar
*format
, va_list ap
);
862 int wxVsprintf( wxChar
*str
, const wxChar
*format
, va_list ap
);
863 #endif /* wxNEED_PRINTF_CONVERSION */
865 /* these 2 can be simply mapped to the versions with underscore at the end */
866 /* if we don't have to do the conversion */
868 However, if we don't have any vswprintf() at all we don't need to redefine
869 anything as our own wxVsnprintf_() already behaves as needed.
871 #if defined(wxNEED_PRINTF_CONVERSION) && defined(wxVsnprintf_)
872 WX_DEFINE_VARARG_FUNC(int, wxSnprintf
, wxDoSnprintf
)
873 int wxDoSnprintf( wxChar
*str
, size_t size
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_3
;
874 int wxVsnprintf( wxChar
*str
, size_t size
, const wxChar
*format
, va_list ap
);
876 #define wxSnprintf wxSnprintf_
877 #define wxVsnprintf wxVsnprintf_
881 various functions which might not be available in libc and for which we
882 provide our own replacements in wxchar.cpp
885 /* ctype.h functions */
887 /* RN: Used only under OSX <= 10.2 currently */
888 #ifdef wxNEED_WX_CTYPE_H
889 WXDLLIMPEXP_BASE
int wxIsalnum(wxChar ch
);
890 WXDLLIMPEXP_BASE
int wxIsalpha(wxChar ch
);
891 WXDLLIMPEXP_BASE
int wxIscntrl(wxChar ch
);
892 WXDLLIMPEXP_BASE
int wxIsdigit(wxChar ch
);
893 WXDLLIMPEXP_BASE
int wxIsgraph(wxChar ch
);
894 WXDLLIMPEXP_BASE
int wxIslower(wxChar ch
);
895 WXDLLIMPEXP_BASE
int wxIsprint(wxChar ch
);
896 WXDLLIMPEXP_BASE
int wxIspunct(wxChar ch
);
897 WXDLLIMPEXP_BASE
int wxIsspace(wxChar ch
);
898 WXDLLIMPEXP_BASE
int wxIsupper(wxChar ch
);
899 WXDLLIMPEXP_BASE
int wxIsxdigit(wxChar ch
);
900 WXDLLIMPEXP_BASE
int wxTolower(wxChar ch
);
901 WXDLLIMPEXP_BASE
int wxToupper(wxChar ch
);
902 #endif /* wxNEED_WX_CTYPE_H */
904 /* under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks */
905 /* the file parsing -- this may be true for 5.0 as well, update #ifdef then */
906 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
908 #define wxIsspace(c) ((((unsigned)(wxChar)c) < 128) && isspace(c))
912 a few compilers don't have the (non standard but common) isascii function,
913 define it ourselves for them
916 #if defined(__MWERKS__)
917 #define wxNEED_ISASCII
918 #elif defined(_WIN32_WCE)
919 #if _WIN32_WCE <= 211
920 #define wxNEED_ISASCII
925 #ifdef wxNEED_ISASCII
926 inline int isascii(int c
) { return (unsigned)c
< 0x80; }
930 #if _WIN32_WCE <= 211
931 #define isspace(c) ((c) == _T(' ') || (c) == _T('\t'))
933 #endif /* _WIN32_WCE */
936 we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
937 initial versions of this header -- now it is too late to remove it so
938 although we fixed the function/macro name above, still provide the
939 backwards-compatible synonym.
941 #define wxIsctrl wxIscntrl
943 /* string.h functions */
945 #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)
946 #define wxNEED_STRDUP
947 #elif defined(__WXWINCE__)
948 #if _WIN32_WCE <= 211
949 #define wxNEED_STRDUP
955 WXDLLIMPEXP_BASE
char *strdup(const char* s
);
958 /* RN: Used only under OSX <= 10.2 currently
959 The __cplusplus ifdefs are messy, but they are required to build
960 the regex library, since c does not support function overloading
962 #ifdef wxNEED_WX_STRING_H
966 WXDLLIMPEXP_BASE wxChar
* wxStrcat(wxChar
*dest
, const wxChar
*src
);
967 WXDLLIMPEXP_BASE
const wxChar
* wxStrchr(const wxChar
*s
, wxChar c
);
968 WXDLLIMPEXP_BASE
int wxStrcmp(const wxChar
*s1
, const wxChar
*s2
);
969 WXDLLIMPEXP_BASE
int wxStrcoll(const wxChar
*s1
, const wxChar
*s2
);
970 WXDLLIMPEXP_BASE wxChar
* wxStrcpy(wxChar
*dest
, const wxChar
*src
);
971 WXDLLIMPEXP_BASE
size_t wxStrcspn(const wxChar
*s
, const wxChar
*reject
);
972 WXDLLIMPEXP_BASE wxChar
* wxStrncat(wxChar
*dest
, const wxChar
*src
, size_t n
);
973 WXDLLIMPEXP_BASE
int wxStrncmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
);
974 WXDLLIMPEXP_BASE wxChar
* wxStrncpy(wxChar
*dest
, const wxChar
*src
, size_t n
);
975 WXDLLIMPEXP_BASE
const wxChar
* wxStrpbrk(const wxChar
*s
, const wxChar
*accept
);
976 WXDLLIMPEXP_BASE
const wxChar
* wxStrrchr(const wxChar
*s
, wxChar c
);
977 WXDLLIMPEXP_BASE
size_t wxStrspn(const wxChar
*s
, const wxChar
*accept
);
978 WXDLLIMPEXP_BASE
const wxChar
* wxStrstr(const wxChar
*haystack
, const wxChar
*needle
);
983 /* These functions use C++, so we can't c extern them */
984 WXDLLIMPEXP_BASE
double wxStrtod(const wxChar
*nptr
, wxChar
**endptr
);
985 WXDLLIMPEXP_BASE
long int wxStrtol(const wxChar
*nptr
, wxChar
**endptr
, int base
);
986 WXDLLIMPEXP_BASE
unsigned long int wxStrtoul(const wxChar
*nptr
, wxChar
**endptr
, int base
);
987 WXDLLIMPEXP_BASE
size_t wxStrxfrm(wxChar
*dest
, const wxChar
*src
, size_t n
);
989 /* inlined versions */
991 inline wxChar
* wxStrchr(wxChar
*s
, wxChar c
)
992 { return (wxChar
*)wxStrchr((const wxChar
*)s
, c
); }
993 inline wxChar
* wxStrpbrk(wxChar
*s
, const wxChar
*accept
)
994 { return (wxChar
*)wxStrpbrk((const wxChar
*)s
, accept
); }
995 inline wxChar
* wxStrrchr(wxChar
*s
, wxChar c
)
996 { return (wxChar
*)wxStrrchr((const wxChar
*)s
, c
); }
997 inline wxChar
*wxStrstr(wxChar
*haystack
, const wxChar
*needle
)
998 { return (wxChar
*)wxStrstr((const wxChar
*)haystack
, needle
); }
1001 #endif /* wxNEED_WX_STRING_H */
1004 WXDLLIMPEXP_BASE
char *wxStrdupA(const char *psz
);
1008 WXDLLIMPEXP_BASE
wchar_t *wxStrdupW(const wchar_t *pwz
);
1012 WXDLLIMPEXP_BASE
int wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
1016 WXDLLIMPEXP_BASE
int wxStrnicmp(const wxChar
*psz1
, const wxChar
*psz2
, size_t len
);
1020 WXDLLIMPEXP_BASE wxChar
* wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
1025 class WXDLLIMPEXP_BASE wxWCharBuffer
;
1026 WXDLLIMPEXP_BASE wxWCharBuffer
wxSetlocale(int category
, const wxChar
*locale
);
1030 /* stdio.h functions */
1031 #ifdef wxNEED_WX_STDIO_H
1033 WXDLLIMPEXP_BASE
FILE * wxFopen(const wxChar
*path
, const wxChar
*mode
);
1034 WXDLLIMPEXP_BASE
FILE * wxFreopen(const wxChar
*path
, const wxChar
*mode
, FILE *stream
);
1035 WXDLLIMPEXP_BASE
int wxRemove(const wxChar
*path
);
1036 WXDLLIMPEXP_BASE
int wxRename(const wxChar
*oldpath
, const wxChar
*newpath
);
1038 /* *printf() family is handled separately */
1039 #endif /* wxNEED_WX_STDIO_H */
1042 /* stdlib.h functions */
1044 WXDLLIMPEXP_BASE
double wxAtof(const wxChar
*psz
);
1047 #ifdef wxNEED_WX_STDLIB_H
1048 WXDLLIMPEXP_BASE
int wxAtoi(const wxChar
*psz
);
1049 WXDLLIMPEXP_BASE
long wxAtol(const wxChar
*psz
);
1050 WXDLLIMPEXP_BASE wxChar
* wxGetenv(const wxChar
*name
);
1051 WXDLLIMPEXP_BASE
int wxSystem(const wxChar
*psz
);
1055 /* time.h functions */
1056 #ifdef wxNEED_WX_TIME_H
1057 #if defined(__MWERKS__) && defined(macintosh)
1060 /*silent gabby compilers*/
1062 WXDLLIMPEXP_BASE
size_t wxStrftime(wxChar
*s
, size_t max
,
1064 const struct tm
*tm
);
1065 #endif /* wxNEED_WX_TIME_H */
1069 WXDLLIMPEXP_BASE wxChar
*wxCtime(const time_t *timep
);
1073 /* missing functions in some WinCE versions */
1075 #if (_WIN32_WCE < 300)
1076 WXDLLIMPEXP_BASE
void *calloc( size_t num
, size_t size
);
1078 #endif /* _WIN32_WCE */
1080 /* multibyte to wide char conversion functions and macros */
1083 /* multibyte<->widechar conversion */
1084 WXDLLIMPEXP_BASE
size_t wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
1085 WXDLLIMPEXP_BASE
size_t wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
1088 #define wxMB2WX wxMB2WC
1089 #define wxWX2MB wxWC2MB
1090 #define wxWC2WX wxStrncpy
1091 #define wxWX2WC wxStrncpy
1093 #define wxMB2WX wxStrncpy
1094 #define wxWX2MB wxStrncpy
1095 #define wxWC2WX wxWC2MB
1096 #define wxWX2WC wxMB2WC
1098 #else /* !wxUSE_UNICODE */
1099 /* Why is this here?
1101 /* No wxUSE_WCHAR_T: we have to do something (JACS) */
1102 #define wxMB2WC wxStrncpy
1103 #define wxWC2MB wxStrncpy
1104 #define wxMB2WX wxStrncpy
1105 #define wxWX2MB wxStrncpy
1106 #define wxWC2WX wxWC2MB
1107 #define wxWX2WC wxMB2WC
1111 RN: The following are not normal versions of memcpy et al., rather
1112 these are either char or widechar versions depending on
1113 if unicode is used or not.
1119 // RN: We could do the usual tricky compiler detection here,
1120 // and use their variant (such as wmemchr, etc.). The problem
1121 // is that these functions are quite rare, even though they are
1122 // part of the current POSIX standard. In addition, most compilers
1123 // (including even MSC) inline them just like we do right in their
1127 #include <string.h> //for mem funcs
1129 //implement our own wmem variants
1130 inline wxChar
* wxTmemchr(const wxChar
* s
, wxChar c
, size_t l
)
1132 for(;l
&& *s
!= c
;--l
, ++s
) {}
1139 inline int wxTmemcmp(const wxChar
* sz1
, const wxChar
* sz2
, size_t len
)
1141 for(; *sz1
== *sz2
&& len
; --len
, ++sz1
, ++sz2
) {}
1144 return *sz1
< *sz2
? -1 : *sz1
> *sz2
;
1149 inline wxChar
* wxTmemcpy(wxChar
* szOut
, const wxChar
* szIn
, size_t len
)
1151 return (wxChar
*) memcpy(szOut
, szIn
, len
* sizeof(wxChar
));
1154 inline wxChar
* wxTmemmove(wxChar
* szOut
, const wxChar
* szIn
, size_t len
)
1156 return (wxChar
*) memmove(szOut
, szIn
, len
* sizeof(wxChar
));
1159 inline wxChar
* wxTmemset(wxChar
* szOut
, const wxChar cIn
, size_t len
)
1161 wxChar
* szRet
= szOut
;
1169 #else /* !wxUSE_UNICODE */
1170 # define wxTmemchr memchr
1171 # define wxTmemcmp memcmp
1172 # define wxTmemcpy memcpy
1173 # define wxTmemmove memmove
1174 # define wxTmemset memset
1175 #endif /* wxUSE_UNICODE/!wxUSE_UNICODE */
1177 #endif /*__cplusplus*/
1179 #endif /* _WX_WXCRT_H_ */