diff --git a/dlls/crtdll/wcstring.c b/dlls/crtdll/wcstring.c index a566b5fa261518497e25a9f1888a41aae5e46989..23696aca69f715d798dcda4685d398bf1eb7e341 100644 --- a/dlls/crtdll/wcstring.c +++ b/dlls/crtdll/wcstring.c @@ -372,22 +372,33 @@ LPWSTR __cdecl CRTDLL_wcstok( LPWSTR str, LPCWSTR delim ) /********************************************************************* * CRTDLL_wcstombs (CRTDLL.521) + * + * FIXME: the reason I do not use wcstombs is that it seems to fail + * for any latin-1 valid character. Not good. */ INT __cdecl CRTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT n ) { - wchar_t *buffer, *p; - int ret; - - int size = (CRTDLL_wcslen(src) + 1) * sizeof(wchar_t); - if (!(buffer = CRTDLL_malloc( size ))) return -1; - p = buffer; - while ((*p++ = (wchar_t)*src++)); - ret = wcstombs( dst, buffer, n ); - CRTDLL_free( buffer ); - return ret; + int copied=0; + while ((n>0) && *src) { + int ret; + /* FIXME: could potentially overflow if we ever have MB of 2 bytes*/ + ret = wctomb(dst,(wchar_t)*src); + if (ret<0) { + /* FIXME: sadly, some versions of glibc do not like latin characters + * as UNICODE chars for some reason (like german umlauts). Just + * copy those anyway. MM 991106 + */ + *dst=*src; + ret = 1; + } + dst += ret; + n -= ret; + copied += ret; + src++; + } + return copied; } - /********************************************************************* * CRTDLL_wctomb (CRTDLL.524) */