msvcrt: Add _strxfrm_l implementation.

This commit is contained in:
Piotr Caban 2014-06-12 17:52:40 +02:00 committed by Alexandre Julliard
parent 80695cde4f
commit 00bce25143
7 changed files with 120 additions and 7 deletions

View file

@ -1367,7 +1367,7 @@
@ cdecl _strupr_l(str ptr) MSVCRT__strupr_l
@ cdecl _strupr_s(str long) MSVCRT__strupr_s
@ cdecl _strupr_s_l(str long ptr) MSVCRT__strupr_s_l
@ stub _strxfrm_l
@ cdecl _strxfrm_l(ptr str long ptr) MSVCRT__strxfrm_l
@ cdecl _swab(str str long) MSVCRT__swab
@ varargs _swprintf(ptr wstr) MSVCRT_swprintf
@ stub _swprintf_c

View file

@ -1725,7 +1725,7 @@
@ cdecl _strupr_l(str ptr) MSVCRT__strupr_l
@ cdecl _strupr_s(str long) MSVCRT__strupr_s
@ cdecl _strupr_s_l(str long ptr) MSVCRT__strupr_s_l
@ stub _strxfrm_l
@ cdecl _strxfrm_l(ptr str long ptr) MSVCRT__strxfrm_l
@ cdecl _swab(str str long) MSVCRT__swab
@ varargs _swprintf(ptr wstr) MSVCRT_swprintf
@ stub _swprintf_c

View file

@ -1047,7 +1047,7 @@
@ cdecl _strupr_l(str ptr) MSVCRT__strupr_l
@ cdecl _strupr_s(str long) MSVCRT__strupr_s
@ cdecl _strupr_s_l(str long ptr) MSVCRT__strupr_s_l
@ stub _strxfrm_l
@ cdecl _strxfrm_l(ptr str long ptr) MSVCRT__strxfrm_l
@ cdecl _swab(str str long) MSVCRT__swab
@ varargs _swprintf(ptr wstr) MSVCRT_swprintf
@ stub _swprintf_c

View file

@ -1022,7 +1022,7 @@
@ cdecl _strupr_l(str ptr) MSVCRT__strupr_l
@ cdecl _strupr_s(str long) MSVCRT__strupr_s
@ cdecl _strupr_s_l(str long ptr) MSVCRT__strupr_s_l
@ stub _strxfrm_l
@ cdecl _strxfrm_l(ptr str long ptr) MSVCRT__strxfrm_l
@ cdecl _swab(str str long) MSVCRT__swab
@ varargs _swprintf(ptr wstr) MSVCRT_swprintf
@ stub _swprintf_c

View file

@ -988,7 +988,7 @@
@ cdecl _strupr_l(str ptr) MSVCRT__strupr_l
@ cdecl _strupr_s(str long) MSVCRT__strupr_s
@ cdecl _strupr_s_l(str long ptr) MSVCRT__strupr_s_l
# stub _strxfrm_l(ptr str long ptr)
@ cdecl _strxfrm_l(ptr str long ptr) MSVCRT__strxfrm_l
@ cdecl _swab(str str long) MSVCRT__swab
@ varargs _swprintf(ptr wstr) MSVCRT_swprintf
# stub _swprintf_c(ptr long str)

View file

@ -700,13 +700,58 @@ char* __cdecl MSVCRT_strncat(char *dst, const char *src, MSVCRT_size_t len)
return strncat(dst, src, len);
}
/*********************************************************************
* _strxfrm_l (MSVCRT.@)
*/
MSVCRT_size_t CDECL MSVCRT__strxfrm_l( char *dest, const char *src,
MSVCRT_size_t len, MSVCRT__locale_t locale )
{
MSVCRT_pthreadlocinfo locinfo;
int ret;
if(!MSVCRT_CHECK_PMT(src)) return INT_MAX;
if(!MSVCRT_CHECK_PMT(dest || !len)) return INT_MAX;
if(len > INT_MAX) {
FIXME("len > INT_MAX not supported\n");
len = INT_MAX;
}
if(!locale)
locinfo = get_locinfo();
else
locinfo = locale->locinfo;
if(!locinfo->lc_handle[MSVCRT_LC_COLLATE]) {
MSVCRT_strncpy(dest, src, len);
return strlen(src);
}
ret = LCMapStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE],
LCMAP_SORTKEY, src, -1, NULL, 0);
if(!ret) {
if(len) dest[0] = 0;
*MSVCRT__errno() = MSVCRT_EILSEQ;
return INT_MAX;
}
if(!len) return ret-1;
if(ret > len) {
dest[0] = 0;
*MSVCRT__errno() = MSVCRT_ERANGE;
return ret-1;
}
return LCMapStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE],
LCMAP_SORTKEY, src, -1, dest, len) - 1;
}
/*********************************************************************
* strxfrm (MSVCRT.@)
*/
MSVCRT_size_t CDECL MSVCRT_strxfrm( char *dest, const char *src, MSVCRT_size_t len )
{
/* FIXME: handle Windows locale */
return strxfrm( dest, src, len );
return MSVCRT__strxfrm_l(dest, src, len, NULL);
}
/********************************************************************

View file

@ -2649,6 +2649,73 @@ static void test_strncpy(void)
ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n");
}
static void test_strxfrm(void)
{
char dest[256];
size_t ret;
/* crashes on old version of msvcrt */
if(p__atodbl_l) {
errno = 0xdeadbeef;
ret = strxfrm(NULL, "src", 1);
ok(ret == INT_MAX, "ret = %d\n", (int)ret);
ok(errno == EINVAL, "errno = %d\n", errno);
errno = 0xdeadbeef;
ret = strxfrm(dest, NULL, 100);
ok(ret == INT_MAX, "ret = %d\n", (int)ret);
ok(errno == EINVAL, "errno = %d\n", errno);
}
ret = strxfrm(NULL, "src", 0);
ok(ret == 3, "ret = %d\n", (int)ret);
dest[0] = 'a';
ret = strxfrm(dest, "src", 0);
ok(ret == 3, "ret = %d\n", (int)ret);
ok(dest[0] == 'a', "dest[0] = %d\n", dest[0]);
dest[3] = 'a';
ret = strxfrm(dest, "src", 5);
ok(ret == 3, "ret = %d\n", (int)ret);
ok(!strcmp(dest, "src"), "dest = %s\n", dest);
errno = 0xdeadbeef;
dest[1] = 'a';
ret = strxfrm(dest, "src", 1);
ok(ret == 3, "ret = %d\n", (int)ret);
ok(dest[0] == 's', "dest[0] = %d\n", dest[0]);
ok(dest[1] == 'a', "dest[1] = %d\n", dest[1]);
ok(errno == 0xdeadbeef, "errno = %d\n", errno);
ret = strxfrm(dest, "", 5);
ok(ret == 0, "ret = %d\n", (int)ret);
ok(!dest[0], "dest[0] = %d\n", dest[0]);
if(!setlocale(LC_ALL, "polish")) {
win_skip("stxfrm tests\n");
return;
}
ret = strxfrm(NULL, "src", 0);
ok(ret < sizeof(dest)-1, "ret = %d\n", (int)ret);
dest[0] = 'a';
ret = strxfrm(dest, "src", 0);
ok(ret < sizeof(dest)-1, "ret = %d\n", (int)ret);
ok(dest[0] == 'a', "dest[0] = %d\n", dest[0]);
ret = strxfrm(dest, "src", ret+1);
ok(ret < sizeof(dest)-1, "ret = %d\n", (int)ret);
ok(dest[0], "dest[0] = 0\n");
errno = 0xdeadbeef;
dest[0] = 'a';
ret = strxfrm(dest, "src", 5);
ok(ret>5 && ret<sizeof(dest)-1, "ret = %d\n", (int)ret);
ok(!dest[0] || broken(!p__atodbl_l && dest[0]=='a'), "dest[0] = %d\n", dest[0]);
setlocale(LC_ALL, "C");
}
START_TEST(string)
{
char mem[100];
@ -2748,4 +2815,5 @@ START_TEST(string)
test__wcstoi64();
test_atoi();
test_strncpy();
test_strxfrm();
}