Index: lib/sdk/crt/printf/streamout.c =================================================================== --- lib/sdk/crt/printf/streamout.c (revision 51001) +++ lib/sdk/crt/printf/streamout.c (working copy) @@ -262,14 +262,16 @@ TCHAR chr; int written = 0; - while (count--) + while (count) { #ifdef _UNICODE int len; - if ((len = mbtowc(&chr, string, MB_CUR_MAX)) < 1) break; + if ((len = mbtowc(&chr, string, count)) < 1) break; string += len; + count -= len; #else chr = *string++; + --count; #endif if (streamout_char(stream, chr) == 0) return -1; written++; Index: lib/sdk/crt/string/mbstowcs_nt.c =================================================================== --- lib/sdk/crt/string/mbstowcs_nt.c (revision 51001) +++ lib/sdk/crt/string/mbstowcs_nt.c (working copy) @@ -4,26 +4,29 @@ #include #include +WCHAR NTAPI RtlAnsiCharToUnicodeChar(IN OUT PUCHAR *AnsiChar); +#undef MB_CUR_MAX +#define MB_CUR_MAX 2 + /* * @implemented */ int mbtowc (wchar_t *wchar, const char *mbchar, size_t count) { - NTSTATUS Status; - ULONG Size; + UCHAR mbarr[MB_CUR_MAX] = { 0 }; + PUCHAR mbs = mbarr; + if (mbchar == NULL) + return 0; + if (wchar == NULL) return 0; - Status = RtlMultiByteToUnicodeN (wchar, - sizeof(WCHAR), - &Size, - mbchar, - count); - if (!NT_SUCCESS(Status)) - return -1; + memcpy(mbarr, mbchar, min(count, sizeof mbarr)); - return (int)Size; + *wchar = RtlAnsiCharToUnicodeChar(&mbs); + + return mbs - mbarr; } /*