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 #define wxHAS_STRTOLL
594 various special cases
597 /* define wxStricmp and wxStrnicmp for various compilers */
599 /* note that in Unicode mode we definitely are going to need our own version */
600 #if !defined(wxStricmp) && !wxUSE_UNICODE
601 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
602 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
603 defined(__EMX__) || defined(__DJGPP__)
604 #define wxStricmp stricmp
605 #define wxStrnicmp strnicmp
606 #elif defined(__WXPALMOS__)
607 /* FIXME: There is no equivalent to strnicmp in the Palm OS API. This
608 * quick hack should do until one can be written.
610 #define wxStricmp StrCaselessCompare
611 #define wxStrnicmp strnicmp
612 #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
613 (defined(__MWERKS__) && defined(__INTEL__))
614 #define wxStricmp _stricmp
615 #define wxStrnicmp _strnicmp
616 #elif defined(__UNIX__) || defined(__GNUWIN32__)
617 #define wxStricmp strcasecmp
618 #define wxStrnicmp strncasecmp
619 /* #else -- use wxWidgets implementation */
621 #endif /* !defined(wxStricmp) */
623 /* define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as */
624 /* it's used in wx/buffer.h -- and also might be used just below by wxStrlen() */
625 /* when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen) */
628 #define wxWcslen wcslen
630 WXDLLIMPEXP_BASE
size_t wxWcslen(const wchar_t *s
);
632 #endif /* wxUSE_WCHAR_T */
635 /* checks whether the passed in pointer is NULL and if the string is empty */
636 inline bool wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
638 /* safe version of strlen() (returns 0 if passed NULL pointer) */
639 inline size_t wxStrlen(const wxChar
*psz
) { return psz
? wxStrlen_(psz
) : 0; }
643 each of strdup() and wcsdup() may or may not be available but we need both
644 of them anyhow for wx/buffer.h so we define the missing one(s) in
645 wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
646 defined -- if this is somehow not the case in some situations, please
647 correct that and not the lines here
650 #define wxStrdup wxStrdupW
652 #define wxStrdup wxStrdupA
656 WXDLLIMPEXP_BASE
bool wxOKlibc(); /* for internal use */
659 /* printf() family saga */
662 For some systems [v]snprintf() exists in the system libraries but not in the
663 headers, so we need to declare it ourselves to be able to use it.
665 #if defined(HAVE_VSNPRINTF) && !defined(HAVE_VSNPRINTF_DECL)
671 int vsnprintf(char *str
, size_t size
, const char *format
, va_list ap
);
672 #endif /* !HAVE_VSNPRINTF_DECL */
674 #if defined(HAVE_SNPRINTF) && !defined(HAVE_SNPRINTF_DECL)
680 WXDLLIMPEXP_BASE
int snprintf(char *str
, size_t size
, const char *format
, ...);
681 #endif /* !HAVE_SNPRINTF_DECL */
683 /* Wrapper for vsnprintf if it's 3rd parameter is non-const. Note: the
684 * same isn't done for snprintf below, the builtin wxSnprintf_ is used
685 * instead since it's already a simple wrapper */
686 #if defined __cplusplus && defined HAVE_BROKEN_VSNPRINTF_DECL
687 inline int wx_fixed_vsnprintf(char *str
, size_t size
, const char *format
, va_list ap
)
689 return vsnprintf(str
, size
, (char*)format
, ap
);
694 MinGW MSVCRT has non-standard vswprintf() (for MSVC compatibility
695 presumably) and normally _vsnwprintf() is used instead
697 #if defined(HAVE_VSWPRINTF) && defined(__MINGW32__)
698 #undef HAVE_VSWPRINTF
701 #if wxUSE_PRINTF_POS_PARAMS
703 The systems where vsnprintf() supports positional parameters should
704 define the HAVE_UNIX98_PRINTF symbol.
706 On systems which don't (e.g. Windows) we are forced to use
707 our wxVsnprintf() implementation.
709 #if defined(HAVE_UNIX98_PRINTF)
711 #ifdef HAVE_VSWPRINTF
712 #define wxVsnprintf_ vswprintf
715 #ifdef HAVE_BROKEN_VSNPRINTF_DECL
716 #define wxVsnprintf_ wx_fixed_vsnprintf
718 #define wxVsnprintf_ vsnprintf
721 #else /* !HAVE_UNIX98_PRINTF */
723 The only compiler with positional parameters support under Windows
724 is VC++ 8.0 which provides a new xxprintf_p() functions family.
725 The 2003 PSDK includes a slightly earlier version of VC8 than the
726 main release and does not have the printf_p functions.
728 #if defined _MSC_FULL_VER && _MSC_FULL_VER >= 140050727 && !defined __WXWINCE__
730 #define wxVsnprintf_ _vswprintf_p
732 #define wxVsnprintf_ _vsprintf_p
735 #endif /* HAVE_UNIX98_PRINTF/!HAVE_UNIX98_PRINTF */
736 #else /* !wxUSE_PRINTF_POS_PARAMS */
738 We always want to define safe snprintf() function to be used instead of
739 sprintf(). Some compilers already have it (or rather vsnprintf() which
740 we really need...), otherwise we implement it using our own printf()
743 We define function with a trailing underscore here because the real one
744 is a wrapper around it as explained below
747 /* first deal with TCHAR-aware compilers which have _vsntprintf */
749 #if defined(__VISUALC__) || \
750 (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
751 #define wxVsnprintf_ _vsntprintf
752 WX_DEFINE_VARARG_FUNC(int, wxSnprintf_
, _sntprintf
)
756 /* if this didn't work, define it separately for Unicode and ANSI builds */
759 #if defined(HAVE__VSNWPRINTF)
760 #define wxVsnprintf_ _vsnwprintf
761 #elif defined(HAVE_VSWPRINTF)
762 #define wxVsnprintf_ vswprintf
763 #elif defined(__WATCOMC__)
764 #define wxVsnprintf_ _vsnwprintf
765 WX_DEFINE_VARARG_FUNC(int, wxSnprintf_
, _snwprintf
)
769 All versions of CodeWarrior supported by wxWidgets apparently
770 have both snprintf() and vsnprintf()
772 #if defined(HAVE_SNPRINTF) \
773 || defined(__MWERKS__) || defined(__WATCOMC__)
774 #ifndef HAVE_BROKEN_SNPRINTF_DECL
775 WX_DEFINE_VARARG_FUNC(int, wxSnprintf_
, snprintf
)
778 #if defined(HAVE_VSNPRINTF) \
779 || defined(__MWERKS__) || defined(__WATCOMC__)
780 #ifdef HAVE_BROKEN_VSNPRINTF_DECL
781 #define wxVsnprintf_ wx_fixed_vsnprintf
783 #define wxVsnprintf_ vsnprintf
786 #endif /* Unicode/ASCII */
787 #endif /* wxVsnprintf_ */
788 #endif /* wxUSE_PRINTF_POS_PARAMS/!wxUSE_PRINTF_POS_PARAMS */
791 /* no snprintf(), cook our own */
793 wxDoSnprintf_(wxChar
*buf
, size_t len
,
794 const wxChar
*format
, ...) ATTRIBUTE_PRINTF_3
;
795 WX_DEFINE_VARARG_FUNC(int, wxSnprintf_
, wxDoSnprintf_
)
798 /* no (suitable) vsnprintf(), cook our own */
800 wxVsnprintf_(wxChar
*buf
, size_t len
,
801 const wxChar
*format
, va_list argptr
);
803 #define wxUSE_WXVSNPRINTF 1
805 #define wxUSE_WXVSNPRINTF 0
809 In Unicode mode we need to have all standard functions such as wprintf() and
810 so on but not all systems have them so use our own implementations in this
813 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
814 #define wxNEED_WPRINTF
818 More Unicode complications: although both ANSI C and C++ define a number of
819 wide character functions such as wprintf(), not all environments have them.
820 Worse, those which do have different behaviours: under Windows, %s format
821 specifier changes its meaning in Unicode build and expects a Unicode string
822 while under Unix/POSIX it still means an ASCII string even for wprintf() and
823 %ls has to be used for wide strings.
825 We choose to always emulate Windows behaviour as more useful for us so even
826 if we have wprintf() we still must wrap it in a non trivial wxPrintf().
830 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
832 we need to implement all wide character printf and scanf functions
833 either because we don't have them at all or because they don't have the
836 WX_DEFINE_VARARG_FUNC(int, wxScanf
, wxDoScanf
)
837 int wxDoScanf( const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_1
;
839 WX_DEFINE_VARARG_FUNC(int, wxSscanf
, wxDoSscanf
)
840 int wxDoSscanf( const wxChar
*str
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
842 WX_DEFINE_VARARG_FUNC(int, wxFscanf
, wxDoFscanf
)
843 int wxDoFscanf( FILE *stream
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
845 WX_DEFINE_VARARG_FUNC(int, wxPrintf
, wxDoPrintf
)
846 int wxDoPrintf( const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_1
;
848 WX_DEFINE_VARARG_FUNC(int, wxSprintf
, wxDoSprintf
)
849 int wxDoSprintf( wxChar
*str
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
851 WX_DEFINE_VARARG_FUNC(int, wxFprintf
, wxDoFprintf
)
852 int wxDoFprintf( FILE *stream
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
854 int wxVsscanf( const wxChar
*str
, const wxChar
*format
, va_list ap
);
855 int wxVfprintf( FILE *stream
, const wxChar
*format
, va_list ap
);
856 int wxVprintf( const wxChar
*format
, va_list ap
);
857 int wxVsprintf( wxChar
*str
, const wxChar
*format
, va_list ap
);
858 #endif /* wxNEED_PRINTF_CONVERSION */
860 /* these 2 can be simply mapped to the versions with underscore at the end */
861 /* if we don't have to do the conversion */
863 However, if we don't have any vswprintf() at all we don't need to redefine
864 anything as our own wxVsnprintf_() already behaves as needed.
866 #if defined(wxNEED_PRINTF_CONVERSION) && defined(wxVsnprintf_)
867 WX_DEFINE_VARARG_FUNC(int, wxSnprintf
, wxDoSnprintf
)
868 int wxDoSnprintf( wxChar
*str
, size_t size
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_3
;
869 int wxVsnprintf( wxChar
*str
, size_t size
, const wxChar
*format
, va_list ap
);
871 #define wxSnprintf wxSnprintf_
872 #define wxVsnprintf wxVsnprintf_
876 various functions which might not be available in libc and for which we
877 provide our own replacements in wxchar.cpp
880 /* ctype.h functions */
882 /* RN: Used only under OSX <= 10.2 currently */
883 #ifdef wxNEED_WX_CTYPE_H
884 WXDLLIMPEXP_BASE
int wxIsalnum(wxChar ch
);
885 WXDLLIMPEXP_BASE
int wxIsalpha(wxChar ch
);
886 WXDLLIMPEXP_BASE
int wxIscntrl(wxChar ch
);
887 WXDLLIMPEXP_BASE
int wxIsdigit(wxChar ch
);
888 WXDLLIMPEXP_BASE
int wxIsgraph(wxChar ch
);
889 WXDLLIMPEXP_BASE
int wxIslower(wxChar ch
);
890 WXDLLIMPEXP_BASE
int wxIsprint(wxChar ch
);
891 WXDLLIMPEXP_BASE
int wxIspunct(wxChar ch
);
892 WXDLLIMPEXP_BASE
int wxIsspace(wxChar ch
);
893 WXDLLIMPEXP_BASE
int wxIsupper(wxChar ch
);
894 WXDLLIMPEXP_BASE
int wxIsxdigit(wxChar ch
);
895 WXDLLIMPEXP_BASE
int wxTolower(wxChar ch
);
896 WXDLLIMPEXP_BASE
int wxToupper(wxChar ch
);
897 #endif /* wxNEED_WX_CTYPE_H */
899 /* under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks */
900 /* the file parsing -- this may be true for 5.0 as well, update #ifdef then */
901 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
903 #define wxIsspace(c) ((((unsigned)(wxChar)c) < 128) && isspace(c))
907 a few compilers don't have the (non standard but common) isascii function,
908 define it ourselves for them
911 #if defined(__MWERKS__)
912 #define wxNEED_ISASCII
913 #elif defined(_WIN32_WCE)
914 #if _WIN32_WCE <= 211
915 #define wxNEED_ISASCII
920 #ifdef wxNEED_ISASCII
921 inline int isascii(int c
) { return (unsigned)c
< 0x80; }
925 #if _WIN32_WCE <= 211
926 #define isspace(c) ((c) == _T(' ') || (c) == _T('\t'))
928 #endif /* _WIN32_WCE */
931 we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
932 initial versions of this header -- now it is too late to remove it so
933 although we fixed the function/macro name above, still provide the
934 backwards-compatible synonym.
936 #define wxIsctrl wxIscntrl
938 /* string.h functions */
940 #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)
941 #define wxNEED_STRDUP
942 #elif defined(__WXWINCE__)
943 #if _WIN32_WCE <= 211
944 #define wxNEED_STRDUP
950 WXDLLIMPEXP_BASE
char *strdup(const char* s
);
953 /* RN: Used only under OSX <= 10.2 currently
954 The __cplusplus ifdefs are messy, but they are required to build
955 the regex library, since c does not support function overloading
957 #ifdef wxNEED_WX_STRING_H
961 WXDLLIMPEXP_BASE wxChar
* wxStrcat(wxChar
*dest
, const wxChar
*src
);
962 WXDLLIMPEXP_BASE
const wxChar
* wxStrchr(const wxChar
*s
, wxChar c
);
963 WXDLLIMPEXP_BASE
int wxStrcmp(const wxChar
*s1
, const wxChar
*s2
);
964 WXDLLIMPEXP_BASE
int wxStrcoll(const wxChar
*s1
, const wxChar
*s2
);
965 WXDLLIMPEXP_BASE wxChar
* wxStrcpy(wxChar
*dest
, const wxChar
*src
);
966 WXDLLIMPEXP_BASE
size_t wxStrcspn(const wxChar
*s
, const wxChar
*reject
);
967 WXDLLIMPEXP_BASE wxChar
* wxStrncat(wxChar
*dest
, const wxChar
*src
, size_t n
);
968 WXDLLIMPEXP_BASE
int wxStrncmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
);
969 WXDLLIMPEXP_BASE wxChar
* wxStrncpy(wxChar
*dest
, const wxChar
*src
, size_t n
);
970 WXDLLIMPEXP_BASE
const wxChar
* wxStrpbrk(const wxChar
*s
, const wxChar
*accept
);
971 WXDLLIMPEXP_BASE
const wxChar
* wxStrrchr(const wxChar
*s
, wxChar c
);
972 WXDLLIMPEXP_BASE
size_t wxStrspn(const wxChar
*s
, const wxChar
*accept
);
973 WXDLLIMPEXP_BASE
const wxChar
* wxStrstr(const wxChar
*haystack
, const wxChar
*needle
);
978 /* These functions use C++, so we can't c extern them */
979 WXDLLIMPEXP_BASE
double wxStrtod(const wxChar
*nptr
, wxChar
**endptr
);
980 WXDLLIMPEXP_BASE
long int wxStrtol(const wxChar
*nptr
, wxChar
**endptr
, int base
);
981 WXDLLIMPEXP_BASE
unsigned long int wxStrtoul(const wxChar
*nptr
, wxChar
**endptr
, int base
);
982 WXDLLIMPEXP_BASE
size_t wxStrxfrm(wxChar
*dest
, const wxChar
*src
, size_t n
);
984 /* inlined versions */
986 inline wxChar
* wxStrchr(wxChar
*s
, wxChar c
)
987 { return (wxChar
*)wxStrchr((const wxChar
*)s
, c
); }
988 inline wxChar
* wxStrpbrk(wxChar
*s
, const wxChar
*accept
)
989 { return (wxChar
*)wxStrpbrk((const wxChar
*)s
, accept
); }
990 inline wxChar
* wxStrrchr(wxChar
*s
, wxChar c
)
991 { return (wxChar
*)wxStrrchr((const wxChar
*)s
, c
); }
992 inline wxChar
*wxStrstr(wxChar
*haystack
, const wxChar
*needle
)
993 { return (wxChar
*)wxStrstr((const wxChar
*)haystack
, needle
); }
996 #endif /* wxNEED_WX_STRING_H */
999 WXDLLIMPEXP_BASE
char *wxStrdupA(const char *psz
);
1003 WXDLLIMPEXP_BASE
wchar_t *wxStrdupW(const wchar_t *pwz
);
1007 WXDLLIMPEXP_BASE
int wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
1011 WXDLLIMPEXP_BASE
int wxStrnicmp(const wxChar
*psz1
, const wxChar
*psz2
, size_t len
);
1015 WXDLLIMPEXP_BASE wxChar
* wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
1020 class WXDLLIMPEXP_BASE wxWCharBuffer
;
1021 WXDLLIMPEXP_BASE wxWCharBuffer
wxSetlocale(int category
, const wxChar
*locale
);
1025 /* stdio.h functions */
1026 #ifdef wxNEED_WX_STDIO_H
1028 WXDLLIMPEXP_BASE
FILE * wxFopen(const wxChar
*path
, const wxChar
*mode
);
1029 WXDLLIMPEXP_BASE
FILE * wxFreopen(const wxChar
*path
, const wxChar
*mode
, FILE *stream
);
1030 WXDLLIMPEXP_BASE
int wxRemove(const wxChar
*path
);
1031 WXDLLIMPEXP_BASE
int wxRename(const wxChar
*oldpath
, const wxChar
*newpath
);
1033 /* *printf() family is handled separately */
1034 #endif /* wxNEED_WX_STDIO_H */
1037 /* stdlib.h functions */
1039 WXDLLIMPEXP_BASE
double wxAtof(const wxChar
*psz
);
1042 #ifdef wxNEED_WX_STDLIB_H
1043 WXDLLIMPEXP_BASE
int wxAtoi(const wxChar
*psz
);
1044 WXDLLIMPEXP_BASE
long wxAtol(const wxChar
*psz
);
1045 WXDLLIMPEXP_BASE wxChar
* wxGetenv(const wxChar
*name
);
1046 WXDLLIMPEXP_BASE
int wxSystem(const wxChar
*psz
);
1050 /* time.h functions */
1051 #ifdef wxNEED_WX_TIME_H
1052 #if defined(__MWERKS__) && defined(macintosh)
1055 /*silent gabby compilers*/
1057 WXDLLIMPEXP_BASE
size_t wxStrftime(wxChar
*s
, size_t max
,
1059 const struct tm
*tm
);
1060 #endif /* wxNEED_WX_TIME_H */
1064 WXDLLIMPEXP_BASE wxChar
*wxCtime(const time_t *timep
);
1068 /* missing functions in some WinCE versions */
1070 #if (_WIN32_WCE < 300)
1071 WXDLLIMPEXP_BASE
void *calloc( size_t num
, size_t size
);
1073 #endif /* _WIN32_WCE */
1075 /* multibyte to wide char conversion functions and macros */
1078 /* multibyte<->widechar conversion */
1079 WXDLLIMPEXP_BASE
size_t wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
1080 WXDLLIMPEXP_BASE
size_t wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
1083 #define wxMB2WX wxMB2WC
1084 #define wxWX2MB wxWC2MB
1085 #define wxWC2WX wxStrncpy
1086 #define wxWX2WC wxStrncpy
1088 #define wxMB2WX wxStrncpy
1089 #define wxWX2MB wxStrncpy
1090 #define wxWC2WX wxWC2MB
1091 #define wxWX2WC wxMB2WC
1093 #else /* !wxUSE_UNICODE */
1094 /* Why is this here?
1096 /* No wxUSE_WCHAR_T: we have to do something (JACS) */
1097 #define wxMB2WC wxStrncpy
1098 #define wxWC2MB wxStrncpy
1099 #define wxMB2WX wxStrncpy
1100 #define wxWX2MB wxStrncpy
1101 #define wxWC2WX wxWC2MB
1102 #define wxWX2WC wxMB2WC
1106 RN: The following are not normal versions of memcpy et al., rather
1107 these are either char or widechar versions depending on
1108 if unicode is used or not.
1114 // RN: We could do the usual tricky compiler detection here,
1115 // and use their variant (such as wmemchr, etc.). The problem
1116 // is that these functions are quite rare, even though they are
1117 // part of the current POSIX standard. In addition, most compilers
1118 // (including even MSC) inline them just like we do right in their
1122 #include <string.h> //for mem funcs
1124 //implement our own wmem variants
1125 inline wxChar
* wxTmemchr(const wxChar
* s
, wxChar c
, size_t l
)
1127 for(;l
&& *s
!= c
;--l
, ++s
) {}
1134 inline int wxTmemcmp(const wxChar
* sz1
, const wxChar
* sz2
, size_t len
)
1136 for(; *sz1
== *sz2
&& len
; --len
, ++sz1
, ++sz2
) {}
1139 return *sz1
< *sz2
? -1 : *sz1
> *sz2
;
1144 inline wxChar
* wxTmemcpy(wxChar
* szOut
, const wxChar
* szIn
, size_t len
)
1146 return (wxChar
*) memcpy(szOut
, szIn
, len
* sizeof(wxChar
));
1149 inline wxChar
* wxTmemmove(wxChar
* szOut
, const wxChar
* szIn
, size_t len
)
1151 return (wxChar
*) memmove(szOut
, szIn
, len
* sizeof(wxChar
));
1154 inline wxChar
* wxTmemset(wxChar
* szOut
, const wxChar cIn
, size_t len
)
1156 wxChar
* szRet
= szOut
;
1164 #else /* !wxUSE_UNICODE */
1165 # define wxTmemchr memchr
1166 # define wxTmemcmp memcmp
1167 # define wxTmemcpy memcpy
1168 # define wxTmemmove memmove
1169 # define wxTmemset memset
1170 #endif /* wxUSE_UNICODE/!wxUSE_UNICODE */
1172 #endif /*__cplusplus*/
1174 #endif /* _WX_WXCRT_H_ */