1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/wxcrt.cpp
3 // Purpose: wxChar CRT wrappers implementation
5 // Modified by: Ron Lee, Francesco Montorsi
8 // Copyright: (c) wxWidgets copyright
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
13 // headers, declarations, constants
14 // ===========================================================================
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
25 #define _ISOC9X_SOURCE 1 // to get vsscanf()
26 #define _BSD_SOURCE 1 // to still get strdup()
36 #include "wx/msw/wince/time.h"
40 #include "wx/string.h"
42 #include "wx/utils.h" // for wxMin and wxMax
46 #if defined(__WIN32__) && defined(wxNEED_WX_CTYPE_H)
54 // there is no errno.h under CE apparently
55 #define wxSET_ERRNO(value)
59 #define wxSET_ERRNO(value) errno = value
62 #if defined(__MWERKS__) && __MSL__ >= 0x6000
68 size_t WXDLLEXPORT
wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
)
70 // assume that we have mbsrtowcs() too if we have wcsrtombs()
73 memset(&mbstate
, 0, sizeof(mbstate_t));
78 if (n
) *buf
= wxT('\0');
82 return mbsrtowcs(buf
, &psz
, n
, &mbstate
);
84 return wxMbstowcs(buf
, psz
, n
);
88 // note that we rely on common (and required by Unix98 but unfortunately not
89 // C99) extension which allows to call mbs(r)towcs() with NULL output pointer
90 // to just get the size of the needed buffer -- this is needed as otherwise
91 // we have no idea about how much space we need and if the CRT doesn't
92 // support it (the only currently known example being Metrowerks, see
93 // wx/crt.h) we don't use its mbstowcs() at all
95 return mbsrtowcs((wchar_t *) NULL
, &psz
, 0, &mbstate
);
97 return wxMbstowcs((wchar_t *) NULL
, psz
, 0);
101 size_t WXDLLEXPORT
wxWC2MB(char *buf
, const wchar_t *pwz
, size_t n
)
103 #ifdef HAVE_WCSRTOMBS
105 memset(&mbstate
, 0, sizeof(mbstate_t));
110 // glibc2.1 chokes on null input
114 #ifdef HAVE_WCSRTOMBS
115 return wcsrtombs(buf
, &pwz
, n
, &mbstate
);
117 return wxWcstombs(buf
, pwz
, n
);
121 #ifdef HAVE_WCSRTOMBS
122 return wcsrtombs((char *) NULL
, &pwz
, 0, &mbstate
);
124 return wxWcstombs((char *) NULL
, pwz
, 0);
127 #endif // wxUSE_WCHAR_T
129 bool WXDLLEXPORT
wxOKlibc()
131 #if wxUSE_WCHAR_T && defined(__UNIX__) && defined(__GLIBC__) && !defined(__WINE__)
132 // glibc 2.0 uses UTF-8 even when it shouldn't
134 if ((MB_CUR_MAX
== 2) &&
135 (wxMB2WC(&res
, "\xdd\xa5", 1) == 1) &&
137 // this is UTF-8 allright, check whether that's what we want
138 char *cur_locale
= setlocale(LC_CTYPE
, NULL
);
139 if ((strlen(cur_locale
) < 4) ||
140 (strcasecmp(cur_locale
+ strlen(cur_locale
) - 4, "utf8")) ||
141 (strcasecmp(cur_locale
+ strlen(cur_locale
) - 5, "utf-8"))) {
142 // nope, don't use libc conversion
150 char* wxSetlocale(int category
, const char *locale
)
152 char *rv
= setlocale(category
, locale
);
153 if ( locale
!= NULL
/* setting locale, not querying */ &&
154 rv
/* call was successful */ )
156 wxUpdateLocaleIsUtf8();
161 // ============================================================================
162 // printf() functions business
163 // ============================================================================
165 // special test mode: define all functions below even if we don't really need
166 // them to be able to test them
176 #define wxNEED_WPRINTF
178 int wxCRT_VfprintfW( FILE *stream
, const wchar_t *format
, va_list argptr
);
182 /* Digital Mars adds count to _stprintf (C99) so convert */
183 int wxCRT_SprintfW (wchar_t * __RESTRICT s
, const wchar_t * __RESTRICT format
, ... )
187 va_start( arglist
, format
);
188 int iLen
= swprintf ( s
, -1, format
, arglist
);
194 // ----------------------------------------------------------------------------
195 // implement the standard IO functions for wide char if libc doesn't have them
196 // ----------------------------------------------------------------------------
199 int wxCRT_FputsW(const wchar_t *ws
, FILE *stream
)
201 wxCharBuffer
buf(wxConvLibc
.cWC2MB(ws
));
205 // counting the number of wide characters written isn't worth the trouble,
206 // simply distinguish between ok and error
207 return wxCRT_FputsA(buf
, stream
) == -1 ?
-1 : 0;
209 #endif // !wxCRT_FputsW
212 int wxCRT_PutsW(const wchar_t *ws
)
214 int rc
= wxCRT_FputsW(ws
, stdout
);
217 if ( wxCRT_FputsW(L
"\n", stdout
) == -1 )
225 #endif // !wxCRT_PutsW
228 int /* not wint_t */ wxCRT_FputcW(wchar_t wc
, FILE *stream
)
230 wchar_t ws
[2] = { wc
, L
'\0' };
232 return wxCRT_FputsW(ws
, stream
);
234 #endif // !wxCRT_FputcW
236 // NB: we only implement va_list functions here, the ones taking ... are
237 // defined below for wxNEED_PRINTF_CONVERSION case anyhow and we reuse
238 // the definitions there to avoid duplicating them here
239 #ifdef wxNEED_WPRINTF
241 // TODO: implement the scanf() functions
242 static int vwscanf(const wchar_t *format
, va_list argptr
)
244 wxFAIL_MSG( _T("TODO") );
249 static int vswscanf(const wchar_t *ws
, const wchar_t *format
, va_list argptr
)
251 // The best we can do without proper Unicode support in glibc is to
252 // convert the strings into MB representation and run ANSI version
253 // of the function. This doesn't work with %c and %s because of difference
254 // in size of char and wchar_t, though.
256 wxCHECK_MSG( wxStrstr(format
, _T("%s")) == NULL
, -1,
257 _T("incomplete vswscanf implementation doesn't allow %s") );
258 wxCHECK_MSG( wxStrstr(format
, _T("%c")) == NULL
, -1,
259 _T("incomplete vswscanf implementation doesn't allow %c") );
261 return vsscanf(wxConvLibc
.cWX2MB(ws
), wxConvLibc
.cWX2MB(format
), argptr
);
264 static int vfwscanf(FILE *stream
, const wchar_t *format
, va_list argptr
)
266 wxFAIL_MSG( _T("TODO") );
271 #define vswprintf wxCRT_VsnprintfW_
273 static int vfwprintf(FILE *stream
, const wchar_t *format
, va_list argptr
)
276 int rc
= s
.PrintfV(format
, argptr
);
280 // we can't do much better without Unicode support in libc...
281 if ( fprintf(stream
, "%s", (const char*)s
.mb_str() ) == -1 )
288 static int vwprintf(const wchar_t *format
, va_list argptr
)
290 return wxCRT_VfprintfW(stdout
, format
, argptr
);
293 #endif // wxNEED_WPRINTF
295 #ifdef wxNEED_PRINTF_CONVERSION
297 // ----------------------------------------------------------------------------
298 // wxFormatConverter: class doing the "%s" -> "%ls" conversion
299 // ----------------------------------------------------------------------------
302 Here are the gory details. We want to follow the Windows/MS conventions,
307 format specifier results in
308 -----------------------------------
314 format specifier results in
315 -----------------------------------
320 while on POSIX systems we have %C identical to %lc and %c always means char
321 (in any mode) while %lc always means wchar_t,
323 So to use native functions in order to get our semantics we must do the
324 following translations in Unicode mode (nothing to do in ANSI mode):
326 wxWidgets specifier POSIX specifier
327 ----------------------------------------
333 And, of course, the same should be done for %s as well.
336 class wxFormatConverter
339 wxFormatConverter(const wchar_t *format
);
341 // notice that we only translated the string if m_fmtOrig == NULL (as set
342 // by CopyAllBefore()), otherwise we should simply use the original format
343 operator const wchar_t *() const
344 { return m_fmtOrig ? m_fmtOrig
: m_fmt
.c_str(); }
347 // copy another character to the translated format: this function does the
348 // copy if we are translating but doesn't do anything at all if we don't,
349 // so we don't create the translated format string at all unless we really
350 // need to (i.e. InsertFmtChar() is called)
351 wchar_t CopyFmtChar(wchar_t ch
)
355 // we're translating, do copy
360 // simply increase the count which should be copied by
361 // CopyAllBefore() later if needed
368 // insert an extra character
369 void InsertFmtChar(wchar_t ch
)
373 // so far we haven't translated anything yet
382 wxASSERT_MSG( m_fmtOrig
&& m_fmt
.empty(), _T("logic error") );
384 m_fmt
= wxString(m_fmtOrig
, m_nCopied
);
386 // we won't need it any longer
390 static bool IsFlagChar(wchar_t ch
)
392 return ch
== _T('-') || ch
== _T('+') ||
393 ch
== _T('0') || ch
== _T(' ') || ch
== _T('#');
396 void SkipDigits(const wchar_t **ptpc
)
398 while ( **ptpc
>= _T('0') && **ptpc
<= _T('9') )
399 CopyFmtChar(*(*ptpc
)++);
402 // the translated format
405 // the original format
406 const wchar_t *m_fmtOrig
;
408 // the number of characters already copied
412 wxFormatConverter
::wxFormatConverter(const wchar_t *format
)
419 if ( CopyFmtChar(*format
++) == _T('%') )
422 while ( IsFlagChar(*format
) )
423 CopyFmtChar(*format
++);
425 // and possible width
426 if ( *format
== _T('*') )
427 CopyFmtChar(*format
++);
432 if ( *format
== _T('.') )
434 CopyFmtChar(*format
++);
435 if ( *format
== _T('*') )
436 CopyFmtChar(*format
++);
441 // next we can have a size modifier
457 // "ll" has a different meaning!
458 if ( format
[1] != _T('l') )
470 // and finally we should have the type
475 // %C and %hC -> %c and %lC -> %lc
477 CopyFmtChar(_T('l'));
479 InsertFmtChar(*format
++ == _T('C') ?
_T('c') : _T('s'));
484 // %c -> %lc but %hc stays %hc and %lc is still %lc
485 if ( size
== Default
)
486 InsertFmtChar(_T('l'));
490 // nothing special to do
491 if ( size
!= Default
)
492 CopyFmtChar(*(format
- 1));
493 CopyFmtChar(*format
++);
499 #else // !wxNEED_PRINTF_CONVERSION
500 // no conversion necessary
501 #define wxFormatConverter(x) (x)
502 #endif // wxNEED_PRINTF_CONVERSION/!wxNEED_PRINTF_CONVERSION
505 // For testing the format converter
506 wxString
wxConvertFormat(const wchar_t *format
)
508 return wxString(wxFormatConverter(format
));
512 // ----------------------------------------------------------------------------
513 // wxPrintf(), wxScanf() and relatives
514 // ----------------------------------------------------------------------------
516 // FIXME-UTF8: do format conversion using (modified) wxFormatConverter in
517 // template wrappers, not here; note that it will needed to
518 // translate all forms of string specifiers to %(l)s for wxPrintf(),
519 // but it only should do what it did in 2.8 for wxScanf()!
521 #ifndef wxCRT_PrintfW
522 int wxCRT_PrintfW( const wchar_t *format
, ... )
525 va_start(argptr
, format
);
527 int ret
= vwprintf( wxFormatConverter(format
), argptr
);
535 #ifndef wxCRT_FprintfW
536 int wxCRT_FprintfW( FILE *stream
, const wchar_t *format
, ... )
539 va_start( argptr
, format
);
541 int ret
= vfwprintf( stream
, wxFormatConverter(format
), argptr
);
549 #ifndef wxCRT_VfprintfW
550 int wxCRT_VfprintfW( FILE *stream
, const wchar_t *format
, va_list argptr
)
552 return vfwprintf( stream
, wxFormatConverter(format
), argptr
);
556 #ifndef wxCRT_VprintfW
557 int wxCRT_VprintfW( const wchar_t *format
, va_list argptr
)
559 return vwprintf( wxFormatConverter(format
), argptr
);
563 #ifndef wxCRT_VsnprintfW
564 int wxCRT_VsnprintfW(wchar_t *str
, size_t size
, const wchar_t *format
, va_list argptr
)
566 return vswprintf( str
, size
, wxFormatConverter(format
), argptr
);
568 #endif // !wxCRT_VsnprintfW
570 // FIXME-UTF8: we only implement widechar version of vsnprintf() in wxprint.cpp,
571 // so this one has to convert the data for now
572 #ifndef wxCRT_VsnprintfA
573 int wxCRT_VsnprintfA(char *buf
, size_t len
, const char *format
, va_list argptr
)
575 wxWCharBuffer
wbuf(len
);
576 int rt
= wxCRT_VsnprintfW(wbuf
.data(), len
,
577 (const wchar_t*)wxConvLibc
.cMB2WC(format
),
579 if ( rt
< 0 || rt
>= (int)len
)
582 if ( wxConvLibc
.FromWChar(buf
, len
, wbuf
) == wxCONV_FAILED
)
587 #endif // !wxCRT_VsnprintfA
589 #ifndef wxCRT_VsprintfW
590 int wxCRT_VsprintfW( wchar_t *str
, const wchar_t *format
, va_list argptr
)
592 // same as for wxSprintf()
593 return vswprintf(str
, INT_MAX
/ 4, wxFormatConverter(format
), argptr
);
598 int wxCRT_ScanfW(const wchar_t *format
, ...)
601 va_start(argptr
, format
);
604 #if (__DECCXX_VER >= 70100000) && !defined(__STD_CFRONT) && !defined( __NONAMESPACE_STD )
605 int ret
= std
::vwscanf(wxFormatConverter(format
), argptr
);
607 int ret
= vwscanf(wxFormatConverter(format
), argptr
);
610 int ret
= vwscanf(wxFormatConverter(format
), argptr
);
619 #ifndef wxCRT_SscanfW
620 int wxCRT_SscanfW(const wchar_t *str
, const wchar_t *format
, ...)
623 va_start(argptr
, format
);
626 #if (__DECCXX_VER >= 70100000) && !defined(__STD_CFRONT) && !defined( __NONAMESPACE_STD )
627 int ret
= std
::vswscanf(str
, wxFormatConverter(format
), argptr
);
629 int ret
= vswscanf(str
, wxFormatConverter(format
), argptr
);
632 int ret
= vswscanf(str
, wxFormatConverter(format
), argptr
);
641 #ifndef wxCRT_FscanfW
642 int wxCRT_FscanfW(FILE *stream
, const wchar_t *format
, ...)
645 va_start(argptr
, format
);
647 #if (__DECCXX_VER >= 70100000) && !defined(__STD_CFRONT) && !defined( __NONAMESPACE_STD )
648 int ret
= std
::vfwscanf(stream
, wxFormatConverter(format
), argptr
);
650 int ret
= vfwscanf(stream
, wxFormatConverter(format
), argptr
);
653 int ret
= vfwscanf(stream
, wxFormatConverter(format
), argptr
);
662 #ifndef wxCRT_VsscanfW
663 int wxCRT_VsscanfW(const wchar_t *str
, const wchar_t *format
, va_list argptr
)
666 #if (__DECCXX_VER >= 70100000) && !defined(__STD_CFRONT) && !defined( __NONAMESPACE_STD )
667 return std
::vswscanf(str
, wxFormatConverter(format
), argptr
);
669 return vswscanf(str
, wxFormatConverter(format
), argptr
);
672 return vswscanf(str
, wxFormatConverter(format
), argptr
);
678 // ----------------------------------------------------------------------------
679 // wrappers to printf and scanf function families
680 // ----------------------------------------------------------------------------
682 #if !wxUSE_UTF8_LOCALE_ONLY
683 int wxDoSprintfWchar(char *str
, const wxChar
*format
, ...)
686 va_start(argptr
, format
);
688 int rv
= wxVsprintf(str
, format
, argptr
);
693 #endif // !wxUSE_UTF8_LOCALE_ONLY
695 #if wxUSE_UNICODE_UTF8
696 int wxDoSprintfUtf8(char *str
, const char *format
, ...)
699 va_start(argptr
, format
);
701 int rv
= wxVsprintf(str
, format
, argptr
);
706 #endif // wxUSE_UNICODE_UTF8
710 #if !wxUSE_UTF8_LOCALE_ONLY
711 int wxDoSprintfWchar(wchar_t *str
, const wxChar
*format
, ...)
714 va_start(argptr
, format
);
716 int rv
= wxVsprintf(str
, format
, argptr
);
721 #endif // !wxUSE_UTF8_LOCALE_ONLY
723 #if wxUSE_UNICODE_UTF8
724 int wxDoSprintfUtf8(wchar_t *str
, const char *format
, ...)
727 va_start(argptr
, format
);
729 int rv
= wxVsprintf(str
, format
, argptr
);
734 #endif // wxUSE_UNICODE_UTF8
736 #endif // wxUSE_UNICODE
738 #if !wxUSE_UTF8_LOCALE_ONLY
739 int wxDoSnprintfWchar(char *str
, size_t size
, const wxChar
*format
, ...)
742 va_start(argptr
, format
);
744 int rv
= wxVsnprintf(str
, size
, format
, argptr
);
749 #endif // !wxUSE_UTF8_LOCALE_ONLY
751 #if wxUSE_UNICODE_UTF8
752 int wxDoSnprintfUtf8(char *str
, size_t size
, const char *format
, ...)
755 va_start(argptr
, format
);
757 int rv
= wxVsnprintf(str
, size
, format
, argptr
);
762 #endif // wxUSE_UNICODE_UTF8
766 #if !wxUSE_UTF8_LOCALE_ONLY
767 int wxDoSnprintfWchar(wchar_t *str
, size_t size
, const wxChar
*format
, ...)
770 va_start(argptr
, format
);
772 int rv
= wxVsnprintf(str
, size
, format
, argptr
);
777 #endif // !wxUSE_UTF8_LOCALE_ONLY
779 #if wxUSE_UNICODE_UTF8
780 int wxDoSnprintfUtf8(wchar_t *str
, size_t size
, const char *format
, ...)
783 va_start(argptr
, format
);
785 int rv
= wxVsnprintf(str
, size
, format
, argptr
);
790 #endif // wxUSE_UNICODE_UTF8
792 #endif // wxUSE_UNICODE
795 #ifdef HAVE_BROKEN_VSNPRINTF_DECL
796 #define vsnprintf wx_fixed_vsnprintf
801 #if !wxUSE_UTF8_LOCALE_ONLY
802 static int ConvertStringToBuf(const wxString
& s
, char *out
, size_t outsize
)
804 const wxWX2WCbuf buf
= s
.wc_str();
806 size_t len
= wxConvLibc
.FromWChar(out
, outsize
, buf
);
807 if ( len
!= wxCONV_FAILED
)
810 return wxConvLibc
.FromWChar(NULL
, 0, buf
);
812 #endif // !wxUSE_UTF8_LOCALE_ONLY
814 #if wxUSE_UNICODE_UTF8
815 static int ConvertStringToBuf(const wxString
& s
, wchar_t *out
, size_t outsize
)
817 const wxWX2WCbuf
buf(s
.wc_str());
818 size_t len
= wxWcslen(buf
);
820 memcpy(out
, buf
, (len
+1) * sizeof(wchar_t));
821 // else: not enough space
824 #endif // wxUSE_UNICODE_UTF8
827 static size_t PrintfViaString(T
*out
, size_t outsize
,
828 const wxString
& format
, va_list argptr
)
831 s
.PrintfV(format
, argptr
);
833 return ConvertStringToBuf(s
, out
, outsize
);
835 #endif // wxUSE_UNICODE
837 int wxVsprintf(char *str
, const wxString
& format
, va_list argptr
)
839 #if wxUSE_UTF8_LOCALE_ONLY
840 return vsprintf(str
, format
.wx_str(), argptr
);
842 #if wxUSE_UNICODE_UTF8
843 if ( wxLocaleIsUtf8
)
844 return vsprintf(str
, format
.wx_str(), argptr
);
848 return PrintfViaString(str
, wxNO_LEN
, format
, argptr
);
850 return wxCRT_VsprintfA(str
, format
.mb_str(), argptr
);
856 int wxVsprintf(wchar_t *str
, const wxString
& format
, va_list argptr
)
858 #if wxUSE_UNICODE_WCHAR
859 return wxCRT_VsprintfW(str
, format
.wc_str(), argptr
);
860 #else // wxUSE_UNICODE_UTF8
861 #if !wxUSE_UTF8_LOCALE_ONLY
862 if ( !wxLocaleIsUtf8
)
863 return wxCRT_VsprintfW(str
, format
.wc_str(), argptr
);
866 return PrintfViaString(str
, wxNO_LEN
, format
, argptr
);
867 #endif // wxUSE_UNICODE_UTF8
869 #endif // wxUSE_UNICODE
871 int wxVsnprintf(char *str
, size_t size
, const wxString
& format
, va_list argptr
)
874 #if wxUSE_UTF8_LOCALE_ONLY
875 rv
= wxCRT_VsnprintfA(str
, size
, format
.wx_str(), argptr
);
877 #if wxUSE_UNICODE_UTF8
878 if ( wxLocaleIsUtf8
)
879 rv
= wxCRT_VsnprintfA(str
, size
, format
.wx_str(), argptr
);
884 // NB: if this code is called, then wxString::PrintV() would use the
885 // wchar_t* version of wxVsnprintf(), so it's safe to use PrintV()
887 rv
= PrintfViaString(str
, size
, format
, argptr
);
890 rv
= wxCRT_VsnprintfA(str
, size
, format
.mb_str(), argptr
);
894 // VsnprintfTestCase reveals that glibc's implementation of vswprintf
895 // doesn't nul terminate on truncation.
902 int wxVsnprintf(wchar_t *str
, size_t size
, const wxString
& format
, va_list argptr
)
906 #if wxUSE_UNICODE_WCHAR
907 rv
= wxCRT_VsnprintfW(str
, size
, format
.wc_str(), argptr
);
908 #else // wxUSE_UNICODE_UTF8
909 #if !wxUSE_UTF8_LOCALE_ONLY
910 if ( !wxLocaleIsUtf8
)
911 rv
= wxCRT_VsnprintfW(str
, size
, format
.wc_str(), argptr
);
915 // NB: if this code is called, then wxString::PrintV() would use the
916 // char* version of wxVsnprintf(), so it's safe to use PrintV()
918 rv
= PrintfViaString(str
, size
, format
, argptr
);
920 #endif // wxUSE_UNICODE_UTF8
922 // VsnprintfTestCase reveals that glibc's implementation of vswprintf
923 // doesn't nul terminate on truncation.
928 #endif // wxUSE_UNICODE
932 // ----------------------------------------------------------------------------
933 // ctype.h stuff (currently unused)
934 // ----------------------------------------------------------------------------
936 #if defined(__WIN32__) && defined(wxNEED_WX_CTYPE_H)
937 static inline WORD
wxMSW_ctype(wchar_t ch
)
940 GetStringTypeEx(LOCALE_USER_DEFAULT
, CT_CTYPE1
, &ch
, 1, &ret
);
944 int wxCRT_IsalnumW(wchar_t ch
) { return IsCharAlphaNumeric(ch
); }
945 int wxCRT_IsalphaW(wchar_t ch
) { return IsCharAlpha(ch
); }
946 int wxCRT_IscntrlW(wchar_t ch
) { return wxMSW_ctype(ch
) & C1_CNTRL
; }
947 int wxCRT_IsdigitW(wchar_t ch
) { return wxMSW_ctype(ch
) & C1_DIGIT
; }
948 int wxCRT_IsgraphW(wchar_t ch
) { return wxMSW_ctype(ch
) & (C1_DIGIT
|C1_PUNCT
|C1_ALPHA
); }
949 int wxCRT_IslowerW(wchar_t ch
) { return IsCharLower(ch
); }
950 int wxCRT_IsprintW(wchar_t ch
) { return wxMSW_ctype(ch
) & (C1_DIGIT
|C1_SPACE
|C1_PUNCT
|C1_ALPHA
); }
951 int wxCRT_IspunctW(wchar_t ch
) { return wxMSW_ctype(ch
) & C1_PUNCT
; }
952 int wxCRT_IsspaceW(wchar_t ch
) { return wxMSW_ctype(ch
) & C1_SPACE
; }
953 int wxCRT_IsupperW(wchar_t ch
) { return IsCharUpper(ch
); }
954 int wxCRT_IsxdigitW(wchar_t ch
) { return wxMSW_ctype(ch
) & C1_XDIGIT
; }
955 int wxCRT_Tolower(wchar_t ch
) { return (wchar_t)CharLower((LPTSTR
)(ch
)); }
956 int wxCRT_Toupper(wchar_t ch
) { return (wchar_t)CharUpper((LPTSTR
)(ch
)); }
959 #ifdef wxNEED_WX_MBSTOWCS
961 WXDLLEXPORT
size_t wxMbstowcs (wchar_t * out
, const char * in
, size_t outlen
)
971 const char* origin
= in
;
973 while (outlen
-- && *in
)
975 *out
++ = (wchar_t) *in
++;
983 WXDLLEXPORT
size_t wxWcstombs (char * out
, const wchar_t * in
, size_t outlen
)
993 const wchar_t* origin
= in
;
995 while (outlen
-- && *in
)
997 *out
++ = (char) *in
++;
1005 #endif // wxNEED_WX_MBSTOWCS
1007 #if defined(wxNEED_WX_CTYPE_H)
1009 #include <CoreFoundation/CoreFoundation.h>
1011 #define cfalnumset CFCharacterSetGetPredefined(kCFCharacterSetAlphaNumeric)
1012 #define cfalphaset CFCharacterSetGetPredefined(kCFCharacterSetLetter)
1013 #define cfcntrlset CFCharacterSetGetPredefined(kCFCharacterSetControl)
1014 #define cfdigitset CFCharacterSetGetPredefined(kCFCharacterSetDecimalDigit)
1015 //CFCharacterSetRef cfgraphset = kCFCharacterSetControl && !' '
1016 #define cflowerset CFCharacterSetGetPredefined(kCFCharacterSetLowercaseLetter)
1017 //CFCharacterSetRef cfprintset = !kCFCharacterSetControl
1018 #define cfpunctset CFCharacterSetGetPredefined(kCFCharacterSetPunctuation)
1019 #define cfspaceset CFCharacterSetGetPredefined(kCFCharacterSetWhitespaceAndNewline)
1020 #define cfupperset CFCharacterSetGetPredefined(kCFCharacterSetUppercaseLetter)
1022 int wxCRT_IsalnumW(wchar_t ch
) { return CFCharacterSetIsCharacterMember(cfalnumset
, ch
); }
1023 int wxCRT_IsalphaW(wchar_t ch
) { return CFCharacterSetIsCharacterMember(cfalphaset
, ch
); }
1024 int wxCRT_IscntrlW(wchar_t ch
) { return CFCharacterSetIsCharacterMember(cfcntrlset
, ch
); }
1025 int wxCRT_IsdigitW(wchar_t ch
) { return CFCharacterSetIsCharacterMember(cfdigitset
, ch
); }
1026 int wxCRT_IsgraphW(wchar_t ch
) { return !CFCharacterSetIsCharacterMember(cfcntrlset
, ch
) && ch
!= ' '; }
1027 int wxCRT_IslowerW(wchar_t ch
) { return CFCharacterSetIsCharacterMember(cflowerset
, ch
); }
1028 int wxCRT_IsprintW(wchar_t ch
) { return !CFCharacterSetIsCharacterMember(cfcntrlset
, ch
); }
1029 int wxCRT_IspunctW(wchar_t ch
) { return CFCharacterSetIsCharacterMember(cfpunctset
, ch
); }
1030 int wxCRT_IsspaceW(wchar_t ch
) { return CFCharacterSetIsCharacterMember(cfspaceset
, ch
); }
1031 int wxCRT_IsupperW(wchar_t ch
) { return CFCharacterSetIsCharacterMember(cfupperset
, ch
); }
1032 int wxCRT_IsxdigitW(wchar_t ch
) { return wxCRT_IsdigitW(ch
) || (ch
>='a' && ch
<='f') || (ch
>='A' && ch
<='F'); }
1034 // FIXME: these are broken!
1035 extern "C" int wxCRT_TolowerW(wchar_t ch
) { return (wchar_t)tolower((char)(ch
)); }
1036 extern "C" int wxCRT_ToupperW(wchar_t ch
) { return (wchar_t)toupper((char)(ch
)); }
1038 #endif // wxNEED_WX_CTYPE_H
1040 #ifndef wxCRT_StrdupA
1041 WXDLLEXPORT
char *wxCRT_StrdupA(const char *s
)
1043 return strcpy((char *)malloc(strlen(s
) + 1), s
);
1045 #endif // wxCRT_StrdupA
1047 #ifndef wxCRT_StrdupW
1048 WXDLLEXPORT
wchar_t * wxCRT_StrdupW(const wchar_t *pwz
)
1050 size_t size
= (wxWcslen(pwz
) + 1) * sizeof(wchar_t);
1051 wchar_t *ret
= (wchar_t *) malloc(size
);
1052 memcpy(ret
, pwz
, size
);
1055 #endif // wxCRT_StrdupW
1057 #ifndef wxCRT_StricmpA
1058 int WXDLLEXPORT
wxCRT_StricmpA(const char *psz1
, const char *psz2
)
1060 register char c1
, c2
;
1062 c1
= wxTolower(*psz1
++);
1063 c2
= wxTolower(*psz2
++);
1064 } while ( c1
&& (c1
== c2
) );
1067 #endif // !defined(wxCRT_StricmpA)
1069 #ifndef wxCRT_StricmpW
1070 int WXDLLEXPORT
wxCRT_StricmpW(const wchar_t *psz1
, const wchar_t *psz2
)
1072 register wchar_t c1
, c2
;
1074 c1
= wxTolower(*psz1
++);
1075 c2
= wxTolower(*psz2
++);
1076 } while ( c1
&& (c1
== c2
) );
1079 #endif // !defined(wxCRT_StricmpW)
1081 #ifndef wxCRT_StrnicmpA
1082 int WXDLLEXPORT
wxCRT_StrnicmpA(const char *s1
, const char *s2
, size_t n
)
1084 // initialize the variables just to suppress stupid gcc warning
1085 register char c1
= 0, c2
= 0;
1086 while (n
&& ((c1
= wxTolower(*s1
)) == (c2
= wxTolower(*s2
)) ) && c1
) n
--, s1
++, s2
++;
1088 if (c1
< c2
) return -1;
1089 if (c1
> c2
) return 1;
1093 #endif // !defined(wxCRT_StrnicmpA)
1095 #ifndef wxCRT_StrnicmpW
1096 int WXDLLEXPORT
wxCRT_StrnicmpW(const wchar_t *s1
, const wchar_t *s2
, size_t n
)
1098 // initialize the variables just to suppress stupid gcc warning
1099 register wchar_t c1
= 0, c2
= 0;
1100 while (n
&& ((c1
= wxTolower(*s1
)) == (c2
= wxTolower(*s2
)) ) && c1
) n
--, s1
++, s2
++;
1102 if (c1
< c2
) return -1;
1103 if (c1
> c2
) return 1;
1107 #endif // !defined(wxCRT_StrnicmpW)
1109 // ----------------------------------------------------------------------------
1110 // string.h functions
1111 // ----------------------------------------------------------------------------
1113 #ifndef wxCRT_StrcatW
1114 WXDLLEXPORT
wchar_t *wxCRT_StrcatW(wchar_t *dest
, const wchar_t *src
)
1116 wchar_t *ret
= dest
;
1117 while (*dest
) dest
++;
1118 while ((*dest
++ = *src
++));
1123 #ifndef wxCRT_StrchrW
1124 WXDLLEXPORT
const wchar_t *wxCRT_StrchrW(const wchar_t *s
, wchar_t c
)
1126 // be careful here as the terminating NUL makes part of the string
1137 #ifndef wxCRT_StrcmpW
1138 WXDLLEXPORT
int wxCRT_StrcmpW(const wchar_t *s1
, const wchar_t *s2
)
1140 while ((*s1
== *s2
) && *s1
) s1
++, s2
++;
1141 if ((wxUChar
)*s1
< (wxUChar
)*s2
) return -1;
1142 if ((wxUChar
)*s1
> (wxUChar
)*s2
) return 1;
1147 #ifndef wxCRT_StrcpyW
1148 WXDLLEXPORT
wchar_t * wxCRT_StrcpyW(wchar_t *dest
, const wchar_t *src
)
1150 wchar_t *ret
= dest
;
1151 while ((*dest
++ = *src
++));
1156 template<typename T
>
1157 static inline size_t wxCRT_DoStrlen(const T
*s
)
1166 // these two (and wxCRT_StrncmpW below) are extern "C" because they are needed
1167 // by regex code, the rest isn't needed, so it's not declared as extern "C"
1168 #ifndef wxCRT_StrlenA
1169 WXDLLEXPORT
size_t wxCRT_StrlenA(const char *s
)
1170 { return wxCRT_DoStrlen(s
); }
1172 #ifndef wxCRT_StrlenW
1173 extern "C" WXDLLEXPORT
size_t wxCRT_StrlenW(const wchar_t *s
)
1174 { return wxCRT_DoStrlen(s
); }
1177 #ifndef wxCRT_StrncatW
1178 WXDLLEXPORT
wchar_t * wxCRT_StrncatW(wchar_t *dest
, const wchar_t *src
, size_t n
)
1180 wchar_t *ret
= dest
;
1181 while (*dest
) dest
++;
1182 while (n
&& (*dest
++ = *src
++)) n
--;
1187 #ifndef wxCRT_StrncmpW
1189 WXDLLEXPORT
int wxCRT_StrncmpW(const wchar_t *s1
, const wchar_t *s2
, size_t n
)
1191 while (n
&& (*s1
== *s2
) && *s1
) n
--, s1
++, s2
++;
1193 if ((wxUChar
)*s1
< (wxUChar
)*s2
) return -1;
1194 if ((wxUChar
)*s1
> (wxUChar
)*s2
) return 1;
1200 #ifndef wxCRT_StrncpyW
1201 WXDLLEXPORT
wchar_t * wxCRT_StrncpyW(wchar_t *dest
, const wchar_t *src
, size_t n
)
1203 wchar_t *ret
= dest
;
1204 while (n
&& (*dest
++ = *src
++)) n
--;
1205 while (n
) *dest
++=0, n
--; // the docs specify padding with zeroes
1210 #ifndef wxCRT_StrpbrkW
1211 WXDLLEXPORT
const wchar_t * wxCRT_StrpbrkW(const wchar_t *s
, const wchar_t *accept
)
1213 while (*s
&& !wxCRT_Strchr(accept
, *s
))
1216 return *s ? s
: NULL
;
1220 #ifndef wxCRT_StrrchrW
1221 WXDLLEXPORT
const wchar_t * wxCRT_StrrchrW(const wchar_t *s
, wchar_t c
)
1223 const wchar_t *ret
= NULL
;
1236 #ifndef wxCRT_StrspnW
1237 WXDLLEXPORT
size_t wxCRT_StrspnW(const wchar_t *s
, const wchar_t *accept
)
1240 while (wxCRT_Strchr(accept
, *s
++)) len
++;
1245 #ifndef wxCRT_StrstrW
1246 WXDLLEXPORT
const wchar_t *wxCRT_StrstrW(const wchar_t *haystack
, const wchar_t *needle
)
1248 wxASSERT_MSG( needle
!= NULL
, _T("NULL argument in wxCRT_Strstr") );
1250 // VZ: this is not exactly the most efficient string search algorithm...
1252 const size_t len
= wxStrlen(needle
);
1254 while ( const wchar_t *fnd
= wxCRT_Strchr(haystack
, *needle
) )
1256 if ( !wxCRT_Strncmp(fnd
, needle
, len
) )
1266 #ifndef wxCRT_StrtodW
1267 WXDLLEXPORT
double wxCRT_StrtodW(const wchar_t *nptr
, wchar_t **endptr
)
1269 const wchar_t *start
= nptr
;
1271 // FIXME: only correct for C locale
1272 while (wxIsspace(*nptr
)) nptr
++;
1273 if (*nptr
== wxT('+') || *nptr
== wxT('-')) nptr
++;
1274 while (wxIsdigit(*nptr
)) nptr
++;
1275 if (*nptr
== wxT('.')) {
1277 while (wxIsdigit(*nptr
)) nptr
++;
1279 if (*nptr
== wxT('E') || *nptr
== wxT('e')) {
1281 if (*nptr
== wxT('+') || *nptr
== wxT('-')) nptr
++;
1282 while (wxIsdigit(*nptr
)) nptr
++;
1285 wxString
data(nptr
, nptr
-start
);
1286 wxWX2MBbuf dat
= data
.mb_str(wxConvLibc
);
1287 char *rdat
= wxMBSTRINGCAST dat
;
1288 double ret
= strtod(dat
, &rdat
);
1290 if (endptr
) *endptr
= (wchar_t *)(start
+ (rdat
- (const char *)dat
));
1294 #endif // !wxCRT_StrtodW
1296 #ifndef wxCRT_StrtolW
1297 WXDLLEXPORT
long int wxCRT_StrtolW(const wchar_t *nptr
, wchar_t **endptr
, int base
)
1299 const wchar_t *start
= nptr
;
1301 // FIXME: only correct for C locale
1302 while (wxIsspace(*nptr
)) nptr
++;
1303 if (*nptr
== wxT('+') || *nptr
== wxT('-')) nptr
++;
1304 if (((base
== 0) || (base
== 16)) &&
1305 (nptr
[0] == wxT('0') && nptr
[1] == wxT('x'))) {
1309 else if ((base
== 0) && (nptr
[0] == wxT('0'))) base
= 8;
1310 else if (base
== 0) base
= 10;
1312 while ((wxIsdigit(*nptr
) && (*nptr
- wxT('0') < base
)) ||
1313 (wxIsalpha(*nptr
) && (wxToupper(*nptr
) - wxT('A') + 10 < base
))) nptr
++;
1315 wxString
data(start
, nptr
-start
);
1316 wxWX2MBbuf dat
= data
.mb_str(wxConvLibc
);
1317 char *rdat
= wxMBSTRINGCAST dat
;
1318 long int ret
= strtol(dat
, &rdat
, base
);
1320 if (endptr
) *endptr
= (wchar_t *)(start
+ (rdat
- (const char *)dat
));
1324 #endif // !wxCRT_StrtolW
1326 #ifndef wxCRT_StrtoulW
1327 WXDLLEXPORT
unsigned long int wxCRT_StrtoulW(const wchar_t *nptr
, wchar_t **endptr
, int base
)
1329 return (unsigned long int) wxCRT_StrtolW(nptr
, endptr
, base
);
1335 #ifndef wxCRT_GetenvW
1336 wchar_t* WXDLLEXPORT
wxCRT_GetenvW(const wchar_t *name
)
1338 // NB: buffer returned by getenv() is allowed to be overwritten next
1339 // time getenv() is called, so it is OK to use static string
1340 // buffer to hold the data.
1341 static wxWCharBuffer
value((wchar_t*)NULL
);
1342 value
= wxConvLibc
.cMB2WC(getenv(wxConvLibc
.cWC2MB(name
)));
1343 return value
.data();
1345 #endif // !wxCRT_GetenvW
1347 #ifndef wxCRT_StrftimeW
1349 wxCRT_StrftimeW(wchar_t *s
, size_t maxsize
, const wchar_t *fmt
, const struct tm
*tm
)
1354 wxCharBuffer
buf(maxsize
);
1356 wxCharBuffer
bufFmt(wxConvLibc
.cWX2MB(fmt
));
1360 size_t ret
= strftime(buf
.data(), maxsize
, bufFmt
, tm
);
1364 wxWCharBuffer wbuf
= wxConvLibc
.cMB2WX(buf
);
1368 wxCRT_StrncpyW(s
, wbuf
, maxsize
);
1369 return wxCRT_StrlenW(s
);
1371 #endif // !wxCRT_StrftimeW
1373 #endif // wxUSE_WCHAR_T
1375 template<typename T
>
1376 static wxULongLong_t
1377 wxCRT_StrtoullBase(const T
* nptr
, T
** endptr
, int base
, T
* sign
)
1379 wxULongLong_t sum
= 0;
1380 wxString
wxstr(nptr
);
1381 wxString
::const_iterator i
= wxstr
.begin();
1382 wxString
::const_iterator end
= wxstr
.end();
1385 while ( i
!= end
&& wxIsspace(*i
) ) i
++;
1387 // Starts with sign?
1392 if ( c
== wxT('+') || c
== wxT('-') )
1400 if ( i
!= end
&& *i
== wxT('0') )
1405 if ( *i
== wxT('x') && (base
== 16 || base
== 0) )
1413 *endptr
= (T
*) nptr
;
1414 wxSET_ERRNO(EINVAL
);
1425 for ( ; i
!= end
; i
++ )
1430 if ( c
>= wxT('0') )
1432 if ( c
<= wxT('9') )
1435 n
= wxTolower(c
) - wxT('a') + 10;
1440 if ( n
>= (unsigned int)base
)
1441 // Invalid character (for this base)
1444 wxULongLong_t prevsum
= sum
;
1445 sum
= (sum
* base
) + n
;
1447 if ( sum
< prevsum
)
1449 wxSET_ERRNO(ERANGE
);
1456 *endptr
= (T
*)(nptr
+ (i
- wxstr
.begin()));
1462 template<typename T
>
1463 static wxULongLong_t
wxCRT_DoStrtoull(const T
* nptr
, T
** endptr
, int base
)
1466 wxULongLong_t uval
= wxCRT_StrtoullBase(nptr
, endptr
, base
, &sign
);
1468 if ( sign
== wxT('-') )
1470 wxSET_ERRNO(ERANGE
);
1477 template<typename T
>
1478 static wxLongLong_t
wxCRT_DoStrtoll(const T
* nptr
, T
** endptr
, int base
)
1481 wxULongLong_t uval
= wxCRT_StrtoullBase(nptr
, endptr
, base
, &sign
);
1482 wxLongLong_t val
= 0;
1484 if ( sign
== wxT('-') )
1486 if ( uval
<= wxULL(wxINT64_MAX
+1) )
1488 if ( uval
== wxULL(wxINT64_MAX
+1))
1489 val
= -((wxLongLong_t
)wxINT64_MAX
) - 1;
1491 val
= -((wxLongLong_t
)uval
);
1495 wxSET_ERRNO(ERANGE
);
1498 else if ( uval
<= wxINT64_MAX
)
1504 wxSET_ERRNO(ERANGE
);
1510 #ifndef wxCRT_StrtollA
1511 wxLongLong_t
wxCRT_StrtollA(const char* nptr
, char** endptr
, int base
)
1512 { return wxCRT_DoStrtoll(nptr
, endptr
, base
); }
1514 #ifndef wxCRT_StrtollW
1515 wxLongLong_t
wxCRT_StrtollW(const wchar_t* nptr
, wchar_t** endptr
, int base
)
1516 { return wxCRT_DoStrtoll(nptr
, endptr
, base
); }
1519 #ifndef wxCRT_StrtoullA
1520 wxULongLong_t
wxCRT_StrtoullA(const char* nptr
, char** endptr
, int base
)
1521 { return wxCRT_DoStrtoull(nptr
, endptr
, base
); }
1523 #ifndef wxCRT_StrtoullW
1524 wxULongLong_t
wxCRT_StrtoullW(const wchar_t* nptr
, wchar_t** endptr
, int base
)
1525 { return wxCRT_DoStrtoull(nptr
, endptr
, base
); }
1528 // ----------------------------------------------------------------------------
1529 // functions which we may need even if !wxUSE_WCHAR_T
1530 // ----------------------------------------------------------------------------
1532 template<typename T
>
1533 static T
*wxCRT_DoStrtok(T
*psz
, const T
*delim
, T
**save_ptr
)
1542 psz
+= wxStrspn(psz
, delim
);
1545 *save_ptr
= (T
*)NULL
;
1550 psz
= wxStrpbrk(psz
, delim
);
1553 *save_ptr
= (T
*)NULL
;
1558 *save_ptr
= psz
+ 1;
1564 #ifndef wxCRT_StrtokA
1565 char *wxCRT_StrtokA(char *psz
, const char *delim
, char **save_ptr
)
1566 { return wxCRT_DoStrtok(psz
, delim
, save_ptr
); }
1568 #ifndef wxCRT_StrtokW
1569 wchar_t *wxCRT_StrtokW(wchar_t *psz
, const wchar_t *delim
, wchar_t **save_ptr
)
1570 { return wxCRT_DoStrtok(psz
, delim
, save_ptr
); }
1573 // ----------------------------------------------------------------------------
1574 // missing C RTL functions
1575 // ----------------------------------------------------------------------------
1577 #ifdef wxNEED_STRDUP
1579 char *strdup(const char *s
)
1581 char *dest
= (char*) malloc( strlen( s
) + 1 ) ;
1583 strcpy( dest
, s
) ;
1586 #endif // wxNEED_STRDUP
1588 #if defined(__WXWINCE__) && (_WIN32_WCE <= 211)
1590 void *calloc( size_t num
, size_t size
)
1592 void** ptr
= (void **)malloc(num
* size
);
1593 memset( ptr
, 0, num
* size
);
1597 #endif // __WXWINCE__ <= 211
1600 int wxCRT_RemoveW(const wchar_t *path
)
1602 return ::DeleteFile(path
) == 0;
1606 #ifndef wxCRT_TmpnamW
1607 wchar_t *wxCRT_TmpnamW(wchar_t *s
)
1609 // tmpnam_r() returns NULL if s=NULL, do the same
1610 wxCHECK_MSG( s
, NULL
, "wxTmpnam must be called with a buffer" );
1613 #define L_tmpnam 1024
1615 wxCharBuffer
buf(L_tmpnam
);
1618 wxConvLibc
.ToWChar(s
, L_tmpnam
+1, buf
.data());
1621 #endif // !wxCRT_TmpnamW
1624 // ============================================================================
1626 // ============================================================================
1628 #if wxUSE_UNICODE_UTF8
1630 #if !wxUSE_UTF8_LOCALE_ONLY
1631 bool wxLocaleIsUtf8
= false; // the safer setting if not known
1634 static bool wxIsLocaleUtf8()
1636 // NB: we intentionally don't use wxLocale::GetSystemEncodingName(),
1637 // because a) it may be unavailable in some builds and b) has slightly
1638 // different semantics (default locale instead of current)
1640 #if defined(HAVE_LANGINFO_H) && defined(CODESET)
1641 // GNU libc provides current character set this way (this conforms to
1643 const char *charset
= nl_langinfo(CODESET
);
1646 // "UTF-8" is used by modern glibc versions, but test other variants
1647 // as well, just in case:
1648 if ( strcmp(charset
, "UTF-8") == 0 ||
1649 strcmp(charset
, "utf-8") == 0 ||
1650 strcmp(charset
, "UTF8") == 0 ||
1651 strcmp(charset
, "utf8") == 0 )
1658 // check if we're running under the "C" locale: it is 7bit subset
1659 // of UTF-8, so it can be safely used with the UTF-8 build:
1660 const char *lc_ctype
= setlocale(LC_CTYPE
, NULL
);
1662 (strcmp(lc_ctype
, "C") == 0 || strcmp(lc_ctype
, "POSIX") == 0) )
1667 // we don't know what charset libc is using, so assume the worst
1672 void wxUpdateLocaleIsUtf8()
1674 #if wxUSE_UTF8_LOCALE_ONLY
1675 if ( !wxIsLocaleUtf8() )
1677 wxLogFatalError(_T("This program requires UTF-8 locale to run."));
1679 #else // !wxUSE_UTF8_LOCALE_ONLY
1680 wxLocaleIsUtf8
= wxIsLocaleUtf8();
1684 #endif // wxUSE_UNICODE_UTF8
1686 // ============================================================================
1687 // wx wrappers for CRT functions
1688 // ============================================================================
1690 #if wxUSE_UNICODE_WCHAR
1691 #define CALL_ANSI_OR_UNICODE(return_kw, callA, callW) return_kw callW
1692 #elif wxUSE_UNICODE_UTF8 && !wxUSE_UTF8_LOCALE_ONLY
1693 #define CALL_ANSI_OR_UNICODE(return_kw, callA, callW) \
1694 return_kw wxLocaleIsUtf8 ? callA : callW
1695 #else // ANSI or UTF8 only
1696 #define CALL_ANSI_OR_UNICODE(return_kw, callA, callW) return_kw callA
1699 int wxPuts(const wxString
& s
)
1701 CALL_ANSI_OR_UNICODE(return,
1702 wxCRT_PutsA(s
.mb_str()),
1703 wxCRT_PutsW(s
.wc_str()));
1706 int wxFputs(const wxString
& s
, FILE *stream
)
1708 CALL_ANSI_OR_UNICODE(return,
1709 wxCRT_FputsA(s
.mb_str(), stream
),
1710 wxCRT_FputsW(s
.wc_str(), stream
));
1713 int wxFputc(const wxUniChar
& c
, FILE *stream
)
1715 #if !wxUSE_UNICODE // FIXME-UTF8: temporary, remove this with ANSI build
1716 return wxCRT_FputcA((char)c
, stream
);
1718 CALL_ANSI_OR_UNICODE(return,
1719 wxCRT_FputsA(c
.AsUTF8(), stream
),
1720 wxCRT_FputcW((wchar_t)c
, stream
));
1724 void wxPerror(const wxString
& s
)
1726 #ifdef wxCRT_PerrorW
1727 CALL_ANSI_OR_UNICODE(wxEMPTY_PARAMETER_VALUE
,
1728 wxCRT_PerrorA(s
.mb_str()),
1729 wxCRT_PerrorW(s
.wc_str()));
1731 wxCRT_PerrorA(s
.mb_str());
1735 wchar_t *wxFgets(wchar_t *s
, int size
, FILE *stream
)
1737 wxCHECK_MSG( s
, NULL
, "empty buffer passed to wxFgets()" );
1739 wxCharBuffer
buf(size
- 1);
1740 // FIXME: this reads too little data if wxConvLibc uses UTF-8 ('size' wide
1741 // characters may be encoded by up to 'size'*4 bytes), but what
1743 if ( wxFgets(buf
.data(), size
, stream
) == NULL
)
1746 if ( wxConvLibc
.ToWChar(s
, size
, buf
, wxNO_LEN
) == wxCONV_FAILED
)
1752 // ----------------------------------------------------------------------------
1753 // wxScanf() and friends
1754 // ----------------------------------------------------------------------------
1757 int wxVsscanf(const char *str
, const char *format
, va_list ap
)
1758 { return wxCRT_VsscanfA(str
, format
, ap
); }
1759 int wxVsscanf(const wchar_t *str
, const wchar_t *format
, va_list ap
)
1760 { return wxCRT_VsscanfW(str
, format
, ap
); }
1761 int wxVsscanf(const wxCharBuffer
& str
, const char *format
, va_list ap
)
1762 { return wxCRT_VsscanfA(str
, format
, ap
); }
1763 int wxVsscanf(const wxWCharBuffer
& str
, const wchar_t *format
, va_list ap
)
1764 { return wxCRT_VsscanfW(str
, format
, ap
); }
1765 int wxVsscanf(const wxString
& str
, const char *format
, va_list ap
)
1766 { return wxCRT_VsscanfA(str
.mb_str(), format
, ap
); }
1767 int wxVsscanf(const wxString
& str
, const wchar_t *format
, va_list ap
)
1768 { return wxCRT_VsscanfW(str
.wc_str(), format
, ap
); }
1769 int wxVsscanf(const wxCStrData
& str
, const char *format
, va_list ap
)
1770 { return wxCRT_VsscanfA(str
.AsCharBuf(), format
, ap
); }
1771 int wxVsscanf(const wxCStrData
& str
, const wchar_t *format
, va_list ap
)
1772 { return wxCRT_VsscanfW(str
.AsWCharBuf(), format
, ap
); }
1773 #endif // !__VISUALC__