Author: gschneider
Date: Thu Dec 18 16:06:07 2008
New Revision: 38182
URL:
http://svn.reactos.org/svn/reactos?rev=38182&view=rev
Log:
- Remove static qualifier from g_mbcp_is_multibyte variable (locale.c) to allow external
reference
- Update _mbccpy, _mbsncpy and _mbsnbcpy, so that they handle leading bytes correctly
- Fixes 6 of 7 failing msvcrt string winetests, the remaining failure is related to memcpy
behavior
Modified:
trunk/reactos/lib/sdk/crt/locale/locale.c
trunk/reactos/lib/sdk/crt/mbstring/mbccpy.c
trunk/reactos/lib/sdk/crt/mbstring/mbsncpy.c
Modified: trunk/reactos/lib/sdk/crt/locale/locale.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/locale/locale.…
==============================================================================
--- trunk/reactos/lib/sdk/crt/locale/locale.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/locale/locale.c [iso-8859-1] Thu Dec 18 16:06:07 2008
@@ -28,7 +28,7 @@
#define MAX_ELEM_LEN 64 /* Max length of country/language/CP string */
unsigned char _mbctype[257] = { 0 };
-static int g_mbcp_is_multibyte = 0;
+int g_mbcp_is_multibyte = 0;
/* It seems that the data about valid trail bytes is not available from kernel32
* so we have to store is here. The format is the same as for lead bytes in CPINFO */
Modified: trunk/reactos/lib/sdk/crt/mbstring/mbccpy.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/mbstring/mbccp…
==============================================================================
--- trunk/reactos/lib/sdk/crt/mbstring/mbccpy.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/mbstring/mbccpy.c [iso-8859-1] Thu Dec 18 16:06:07 2008
@@ -1,15 +1,23 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS system libraries
+ * FILE: lib/sdk/crt/mbstring/mbccpy.c
+ * PURPOSE: Copies a multi byte character
+ * PROGRAMERS:
+ * Copyright 1999 Alexandre Julliard
+ * Copyright 2000 Jon Griffths
+ *
+ */
+
#include <mbstring.h>
#include <string.h>
-
-size_t _mbclen2(const unsigned int s);
/*
* @implemented
*/
void _mbccpy(unsigned char *dst, const unsigned char *src)
{
- if (!_ismbblead(*src) )
- return;
-
- memcpy(dst,src,_mbclen2(*src));
+ *dst = *src;
+ if(_ismbblead(*src))
+ *++dst = *++src; /* MB char */
}
Modified: trunk/reactos/lib/sdk/crt/mbstring/mbsncpy.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/mbstring/mbsnc…
==============================================================================
--- trunk/reactos/lib/sdk/crt/mbstring/mbsncpy.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/mbstring/mbsncpy.c [iso-8859-1] Thu Dec 18 16:06:07 2008
@@ -3,48 +3,55 @@
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/mbstring/mbsncpy.c
* PURPOSE: Copies a string to a maximum of n bytes or characters
- * PROGRAMER: Ariadne
- * UPDATE HISTORY:
- * 12/04/99: Created
+ * PROGRAMERS:
+ * Copyright 1999 Ariadne
+ * Copyright 1999 Alexandre Julliard
+ * Copyright 2000 Jon Griffths
+ *
*/
#include <mbstring.h>
+extern int g_mbcp_is_multibyte;
/*
* @implemented
*/
-unsigned char* _mbsncpy(unsigned char *str1, const unsigned char *str2, size_t n)
+unsigned char* _mbsncpy(unsigned char *dst, const unsigned char *src, size_t n)
{
- unsigned char *s1 = (unsigned char *)str1;
- unsigned char *s2 = (unsigned char *)str2;
+ unsigned char* ret = dst;
+ if(!n)
+ return dst;
+ if (g_mbcp_is_multibyte)
+ {
+ while (*src && n)
+ {
+ n--;
+ if (_ismbblead(*src))
+ {
+ if (!*(src+1))
+ {
+ *dst++ = 0;
+ *dst++ = 0;
+ break;
+ }
- unsigned short *short_s1, *short_s2;
+ *dst++ = *src++;
+ }
- if (n == 0)
- return 0;
- do {
-
- if (*s2 == 0)
- break;
-
- if ( !_ismbblead(*s2) ) {
-
- *s1 = *s2;
- s1 += 1;
- s2 += 1;
- n--;
- }
- else {
- short_s1 = (unsigned short *)s1;
- short_s2 = (unsigned short *)s2;
- *short_s1 = *short_s2;
- s1 += 2;
- s2 += 2;
- n--;
- }
- } while (n > 0);
- return str1;
+ *dst++ = *src++;
+ }
+ }
+ else
+ {
+ while (n)
+ {
+ n--;
+ if (!(*dst++ = *src++)) break;
+ }
+ }
+ while (n--) *dst++ = 0;
+ return ret;
}
@@ -55,37 +62,32 @@
*
* @implemented
*/
-unsigned char * _mbsnbcpy(unsigned char *str1, const unsigned char *str2, size_t n)
+unsigned char * _mbsnbcpy(unsigned char *dst, const unsigned char *src, size_t n)
{
- unsigned char *s1 = (unsigned char *)str1;
- unsigned char *s2 = (unsigned char *)str2;
+ unsigned char* ret = dst;
+ if(!n)
+ return dst;
+ if(g_mbcp_is_multibyte)
+ {
+ int is_lead = 0;
+ while (*src && n)
+ {
+ is_lead = (!is_lead && _ismbblead(*src));
+ n--;
+ *dst++ = *src++;
+ }
- unsigned short *short_s1, *short_s2;
-
- if (n == 0)
- return 0;
- do {
-
- if (*s2 == 0) {
- *s1 = *s2;
- break;
- }
-
- if ( !_ismbblead(*s2) ) {
-
- *s1 = *s2;
- s1 += 1;
- s2 += 1;
- n--;
- }
- else {
- short_s1 = (unsigned short *)s1;
- short_s2 = (unsigned short *)s2;
- *short_s1 = *short_s2;
- s1 += 2;
- s2 += 2;
- n-=2;
- }
- } while (n > 0);
- return str1;
+ if (is_lead) /* if string ends with a lead, remove it */
+ *(dst - 1) = 0;
+ }
+ else
+ {
+ while (n)
+ {
+ n--;
+ if (!(*dst++ = *src++)) break;
+ }
+ }
+ while (n--) *dst++ = 0;
+ return ret;
}