diff --git a/include/wx/wxchar.h b/include/wx/wxchar.h index 6d560af956..5320075a0f 100644 --- a/include/wx/wxchar.h +++ b/include/wx/wxchar.h @@ -389,8 +389,28 @@ #define wxMbstowcs mbstowcs #define wxWcstombs wcstombs #else /* !TCHAR-aware compilers */ + /* + There are 2 unrelated problems with these functions under Mac: + a) Metrowerks MSL CRT implements them strictly in C99 sense and + doesn't support (very common) extension of allowing to call + mbstowcs(NULL, ...) which makes it pretty useless as you can't + know the size of the needed buffer + b) OS X <= 10.2 declares and even defined these functions but + doesn't really implement them -- they always return an error - #if !defined(__MWERKS__) && defined(__DARWIN__) && ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 ) + So use our own replacements in both cases. + */ + #if defined(__MWERKS__) + #define wxNEED_WX_MBSTOWCS + #endif + + #ifdef __DARWIN__ + #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 + #define wxNEED_WX_MBSTOWCS + #endif + #endif + + #ifdef wxNEED_WX_MBSTOWCS /* even though they are defined and "implemented", they are bad and just stubs so we need our own - we need these even in ANSI builds!! */ WXDLLIMPEXP_BASE size_t wxMbstowcs (wchar_t *, const char *, size_t); diff --git a/src/common/wxchar.cpp b/src/common/wxchar.cpp index 65024d40d8..b3f6003eea 100644 --- a/src/common/wxchar.cpp +++ b/src/common/wxchar.cpp @@ -1066,7 +1066,7 @@ WXDLLEXPORT int wxTolower(wxChar ch) { return (wxChar)CharLower((LPTSTR)(ch)); } WXDLLEXPORT int wxToupper(wxChar ch) { return (wxChar)CharUpper((LPTSTR)(ch)); } #endif -#if defined(__DARWIN__) && ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 ) +#ifdef wxNEED_WX_MBSTOWCS WXDLLEXPORT size_t wxMbstowcs (wchar_t * out, const char * in, size_t outlen) { @@ -1112,6 +1112,8 @@ WXDLLEXPORT size_t wxWcstombs (char * out, const wchar_t * in, size_t outlen) return in - origin; } +#endif // wxNEED_WX_MBSTOWCS + #if defined(wxNEED_WX_CTYPE_H) #include @@ -1143,8 +1145,6 @@ WXDLLEXPORT int wxToupper(wxChar ch) { return (wxChar)toupper((char)(ch)); } #endif // wxNEED_WX_CTYPE_H -#endif // defined(__DARWIN__) and OSX <= 10.2 - #ifndef wxStrdupA WXDLLEXPORT char *wxStrdupA(const char *s)