From: Bartosz Kosiorek gang65@poczta.onet.pl
--- dlls/msvcr100/msvcr100.spec | 2 +- dlls/msvcr110/msvcr110.spec | 2 +- dlls/msvcr120/msvcr120.spec | 2 +- dlls/msvcr80/msvcr80.spec | 2 +- dlls/msvcr90/msvcr90.spec | 2 +- dlls/msvcrt/mbcs.c | 65 ++++++++++++++++++++++++------------- dlls/msvcrt/msvcrt.spec | 2 +- dlls/msvcrt/tests/string.c | 15 +++++---- dlls/ucrtbase/ucrtbase.spec | 4 +-- 9 files changed, 59 insertions(+), 37 deletions(-)
diff --git a/dlls/msvcr100/msvcr100.spec b/dlls/msvcr100/msvcr100.spec index 9659cd1f3a2..5996051d5ed 100644 --- a/dlls/msvcr100/msvcr100.spec +++ b/dlls/msvcr100/msvcr100.spec @@ -1096,7 +1096,7 @@ @ extern _mbctype MSVCRT_mbctype @ stub _mblen_l @ cdecl _mbsbtype(str long) -@ stub _mbsbtype_l +@ cdecl _mbsbtype_l(str long ptr) @ cdecl _mbscat_s(ptr long str) @ cdecl _mbscat_s_l(ptr long str ptr) @ cdecl _mbschr(str long) diff --git a/dlls/msvcr110/msvcr110.spec b/dlls/msvcr110/msvcr110.spec index 4bab0eddc99..1dacd170343 100644 --- a/dlls/msvcr110/msvcr110.spec +++ b/dlls/msvcr110/msvcr110.spec @@ -1453,7 +1453,7 @@ @ extern _mbctype MSVCRT_mbctype @ stub _mblen_l @ cdecl _mbsbtype(str long) -@ stub _mbsbtype_l +@ cdecl _mbsbtype_l(str long ptr) @ cdecl _mbscat_s(ptr long str) @ cdecl _mbscat_s_l(ptr long str ptr) @ cdecl _mbschr(str long) diff --git a/dlls/msvcr120/msvcr120.spec b/dlls/msvcr120/msvcr120.spec index e0d87f7f7f1..b0e7c83101c 100644 --- a/dlls/msvcr120/msvcr120.spec +++ b/dlls/msvcr120/msvcr120.spec @@ -1464,7 +1464,7 @@ @ extern _mbctype MSVCRT_mbctype @ stub _mblen_l @ cdecl _mbsbtype(str long) -@ stub _mbsbtype_l +@ cdecl _mbsbtype_l(str long ptr) @ cdecl _mbscat_s(ptr long str) @ cdecl _mbscat_s_l(ptr long str ptr) @ cdecl _mbschr(str long) diff --git a/dlls/msvcr80/msvcr80.spec b/dlls/msvcr80/msvcr80.spec index 5cc72177a33..68660cd6e87 100644 --- a/dlls/msvcr80/msvcr80.spec +++ b/dlls/msvcr80/msvcr80.spec @@ -768,7 +768,7 @@ @ extern _mbctype MSVCRT_mbctype @ stub _mblen_l @ cdecl _mbsbtype(str long) -@ stub _mbsbtype_l +@ cdecl _mbsbtype_l(str long ptr) @ cdecl _mbscat_s(ptr long str) @ cdecl _mbscat_s_l(ptr long str ptr) @ cdecl _mbschr(str long) diff --git a/dlls/msvcr90/msvcr90.spec b/dlls/msvcr90/msvcr90.spec index 556ba1fa1a7..5f38afdbdfc 100644 --- a/dlls/msvcr90/msvcr90.spec +++ b/dlls/msvcr90/msvcr90.spec @@ -746,7 +746,7 @@ @ extern _mbctype MSVCRT_mbctype @ stub _mblen_l @ cdecl _mbsbtype(str long) -@ stub _mbsbtype_l +@ cdecl _mbsbtype_l(str long ptr) @ cdecl _mbscat_s(ptr long str) @ cdecl _mbscat_s_l(ptr long str ptr) @ cdecl _mbschr(str long) diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c index 23d0bbbaeb8..abb5f574ba1 100644 --- a/dlls/msvcrt/mbcs.c +++ b/dlls/msvcrt/mbcs.c @@ -2028,34 +2028,55 @@ int CDECL _mbbtype(unsigned char c, int type) }
/********************************************************************* - * _mbsbtype (MSVCRT.@) + * _mbsbtype_l (MSVCRT.@) */ -int CDECL _mbsbtype(const unsigned char *str, size_t count) +int CDECL _mbsbtype_l(const unsigned char *str, size_t count, _locale_t locale) { - int lead = 0; - const unsigned char *end = str + count; + int lead = 0; + pthreadmbcinfo mbcinfo; + const unsigned char *end = str + count;
- /* Lead bytes can also be trail bytes so we need to analyse the string. - * Also we must return _MBC_ILLEGAL for chars past the end of the string - */ - while (str < end) /* Note: we skip the last byte - will check after the loop */ - { - if (!*str) - return _MBC_ILLEGAL; - lead = get_mbcinfo()->ismbcodepage && !lead && _ismbblead(*str); - str++; - } + if (!MSVCRT_CHECK_PMT(str)) + return _MBC_ILLEGAL;
- if (lead) - if (_ismbbtrail(*str)) - return _MBC_TRAIL; + if (locale) + mbcinfo = locale->mbcinfo; else - return _MBC_ILLEGAL; - else - if (_ismbblead(*str)) - return _MBC_LEAD; + mbcinfo = get_mbcinfo(); + + /* Lead bytes can also be trail bytes so we need to analyse the string. + * Also we must return _MBC_ILLEGAL for chars past the end of the string + */ + while (str < end) /* Note: we skip the last byte - will check after the loop */ + { + if (!*str) + return _MBC_ILLEGAL; + lead = mbcinfo->ismbcodepage && !lead && _ismbblead_l(*str, locale); + str++; + } + + if (lead) + { + if (_ismbbtrail_l(*str, locale)) + return _MBC_TRAIL; + else + return _MBC_ILLEGAL; + } else - return _MBC_SINGLE; + { + if (_ismbblead_l(*str, locale)) + return _MBC_LEAD; + else + return _MBC_SINGLE; + } +} + +/********************************************************************* + * _mbsbtype (MSVCRT.@) + */ +int CDECL _mbsbtype(const unsigned char *str, size_t count) +{ + return _mbsbtype_l(str, count, NULL); }
/********************************************************************* diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec index e5e938959b8..7d7c81f72dd 100644 --- a/dlls/msvcrt/msvcrt.spec +++ b/dlls/msvcrt/msvcrt.spec @@ -713,7 +713,7 @@ @ extern _mbctype MSVCRT_mbctype # stub _mblen_l(str long ptr) @ cdecl _mbsbtype(str long) -# stub _mbsbtype_l(str long ptr) +@ cdecl _mbsbtype_l(str long ptr) @ cdecl _mbscat(str str) @ cdecl _mbscat_s(ptr long str) @ cdecl _mbscat_s_l(ptr long str ptr) diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c index cdc19736832..d64e90b9ec6 100644 --- a/dlls/msvcrt/tests/string.c +++ b/dlls/msvcrt/tests/string.c @@ -133,13 +133,13 @@ static void test_swab( void ) { char expected1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#"; char expected2[] = "ABCDEFGHIJKLMNOPQRSTUVWX$"; char expected3[] = "$"; - + char from[30]; char to[30]; - + int testsize; - - /* Test 1 - normal even case */ + + /* Test 1 - normal even case */ memset(to,'$', sizeof(to)); memset(from,'@', sizeof(from)); testsize = 26; @@ -147,7 +147,7 @@ static void test_swab( void ) { _swab( from, to, testsize ); ok(memcmp(to,expected1,testsize) == 0, "Testing even size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
- /* Test 2 - uneven case */ + /* Test 2 - uneven case */ memset(to,'$', sizeof(to)); memset(from,'@', sizeof(from)); testsize = 25; @@ -155,7 +155,7 @@ static void test_swab( void ) { _swab( from, to, testsize ); ok(memcmp(to,expected2,testsize) == 0, "Testing odd size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
- /* Test 3 - from = to */ + /* Test 3 - from = to */ memset(to,'$', sizeof(to)); memset(from,'@', sizeof(from)); testsize = 26; @@ -163,7 +163,7 @@ static void test_swab( void ) { _swab( to, to, testsize ); ok(memcmp(to,expected1,testsize) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
- /* Test 4 - 1 bytes */ + /* Test 4 - 1 bytes */ memset(to,'$', sizeof(to)); memset(from,'@', sizeof(from)); testsize = 1; @@ -335,6 +335,7 @@ static void test_mbcp(void) expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");
/* _mbsbtype */ + expect_eq(_mbsbtype(NULL, 0), _MBC_ILLEGAL, int, "%d"); expect_eq(_mbsbtype(mbstring, 0), _MBC_LEAD, int, "%d"); expect_eq(_mbsbtype(mbstring, 1), _MBC_TRAIL, int, "%d"); expect_eq(_mbsbtype(mbstring, 2), _MBC_LEAD, int, "%d"); diff --git a/dlls/ucrtbase/ucrtbase.spec b/dlls/ucrtbase/ucrtbase.spec index 33c66e2f0b3..995237dcc5c 100644 --- a/dlls/ucrtbase/ucrtbase.spec +++ b/dlls/ucrtbase/ucrtbase.spec @@ -611,7 +611,7 @@ @ cdecl _mbctoupper_l(long ptr) @ stub _mblen_l @ cdecl _mbsbtype(str long) -@ stub _mbsbtype_l +@ cdecl _mbsbtype_l(str long ptr) @ cdecl _mbscat_s(ptr long str) @ cdecl _mbscat_s_l(ptr long str ptr) @ cdecl _mbschr(str long) @@ -1181,7 +1181,7 @@ @ cdecl _o__mbctoupper_l(long ptr) _mbctoupper_l @ stub _o__mblen_l @ cdecl _o__mbsbtype(str long) _mbsbtype -@ stub _o__mbsbtype_l +@ cdecl _o__mbsbtype_l(str long ptr) _mbsbtype_l @ cdecl _o__mbscat_s(ptr long str) _mbscat_s @ cdecl _o__mbscat_s_l(ptr long str ptr) _mbscat_s_l @ cdecl _o__mbschr(str long) _mbschr