[ros-diffs] [tkreuzer] 51003: [CRT] Patch by Thomas Faber: Fix nt version of mbstowcs. See issue #5983 for more details.

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Wed Mar 9 15:29:15 UTC 2011


Author: tkreuzer
Date: Wed Mar  9 15:29:13 2011
New Revision: 51003

URL: http://svn.reactos.org/svn/reactos?rev=51003&view=rev
Log:
[CRT]
Patch by Thomas Faber: Fix nt version of mbstowcs.

See issue #5983 for more details.

Modified:
    trunk/reactos/lib/sdk/crt/string/mbstowcs_nt.c

Modified: trunk/reactos/lib/sdk/crt/string/mbstowcs_nt.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/string/mbstowcs_nt.c?rev=51003&r1=51002&r2=51003&view=diff
==============================================================================
--- trunk/reactos/lib/sdk/crt/string/mbstowcs_nt.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/string/mbstowcs_nt.c [iso-8859-1] Wed Mar  9 15:29:13 2011
@@ -4,26 +4,35 @@
 #include <ndk/rtlfuncs.h>
 #include <string.h>
 
+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;
+	WCHAR wc;
+
+	if (mbchar == NULL)
+		return 0;
 
 	if (wchar == NULL)
 		return 0;
 
-	Status = RtlMultiByteToUnicodeN (wchar,
-	                                 sizeof(WCHAR),
-	                                 &Size,
-	                                 mbchar,
-	                                 count);
-	if (!NT_SUCCESS(Status))
+	memcpy(mbarr, mbchar, min(count, sizeof mbarr));
+
+	wc = RtlAnsiCharToUnicodeChar(&mbs);
+
+	if (wc == L' ' && mbarr[0] != ' ')
 		return -1;
 
-	return (int)Size;
+	*wchar = wc;
+
+	return mbs - mbarr;
 }
 
 /*




More information about the Ros-diffs mailing list