From 8dbc9d62bc047accdf9814cb958cb95f3fc3723d Mon Sep 17 00:00:00 2001 From: crs Date: Tue, 22 Oct 2002 22:35:13 +0000 Subject: [PATCH] Added workarounds for missing reentrant versions of wide char to/from multi-byte conversion functions. --- configure.in | 2 ++ lib/io/CUnicode.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/configure.in b/configure.in index 56346272..b92c7539 100644 --- a/configure.in +++ b/configure.in @@ -52,6 +52,7 @@ AC_TYPE_SIZE_T dnl checks for structures AC_STRUCT_TM +AC_CHECK_TYPES(mbstate_t,,,[#include ]) dnl checks for compiler characteristics AC_CHECK_SIZEOF(char, 1) @@ -72,6 +73,7 @@ AC_FUNC_STRFTIME AC_CHECK_FUNCS(gmtime_r) AC_CHECK_FUNCS(getpwuid_r) AC_CHECK_FUNCS(vsnprintf) +AC_CHECK_FUNCS(wcrtomb mbrtowc mbsinit) AC_FUNC_SELECT_ARGTYPES ACX_CHECK_POLL dnl use AC_REPLACE_FUNCS() for stuff in string.h diff --git a/lib/io/CUnicode.cpp b/lib/io/CUnicode.cpp index 383d2381..ada84841 100644 --- a/lib/io/CUnicode.cpp +++ b/lib/io/CUnicode.cpp @@ -70,6 +70,61 @@ setError(bool* errors) } } +// +// multibyte conversion stuff when reentrant versions not available +// + +#if !HAVE_MBSTATE_T +struct mbstate_t { int m_dummy; }; +#undef HAVE_MBSINIT +#undef HAVE_MBRTOWC +#undef HAVE_WCRTOMB +#endif + +#if !HAVE_MBSINIT +static +int +mbsinit(const mbstate_t*) +{ + return 1; +} +#endif + +#if !HAVE_MBRTOWC +#include "CLock.h" +#include "CMutex.h" + +static CMutex s_mbrtowcMutex; + +static +size_t +mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t*) +{ + CLock lock(&s_mbrtowcMutex); + int result = mbtowc(pwc, s, n); + if (result < 0) + return (size_t)-1; + else + return result; +} +#endif + +#if !HAVE_WCRTOMB +#include "CLock.h" +#include "CMutex.h" + +static CMutex s_wcrtombMutex; + +static +size_t +wcrtomb(char* s, wchar_t wc, mbstate_t*) +{ + CLock lock(&s_wcrtombMutex); + return (size_t)wctomb(s, wc); +} +#endif + + // // CUnicode //