Commit 5098bab5 authored by Bartosz Kosiorek's avatar Bartosz Kosiorek Committed by Alexandre Julliard

msvcrt: Add _mbsncpy_l implementation.

parent 2a89257b
......@@ -1156,7 +1156,7 @@
@ stub _mbsncoll(str str long)
@ stub _mbsncoll_l
@ cdecl _mbsncpy(ptr str long)
@ stub _mbsncpy_l
@ cdecl _mbsncpy_l(ptr str long ptr)
@ stub _mbsncpy_s
@ stub _mbsncpy_s_l
@ cdecl _mbsnextc(str)
......
......@@ -1513,7 +1513,7 @@
@ stub _mbsncoll(str str long)
@ stub _mbsncoll_l
@ cdecl _mbsncpy(ptr str long)
@ stub _mbsncpy_l
@ cdecl _mbsncpy_l(ptr str long ptr)
@ stub _mbsncpy_s
@ stub _mbsncpy_s_l
@ cdecl _mbsnextc(str)
......
......@@ -1524,7 +1524,7 @@
@ stub _mbsncoll(str str long)
@ stub _mbsncoll_l
@ cdecl _mbsncpy(ptr str long)
@ stub _mbsncpy_l
@ cdecl _mbsncpy_l(ptr str long ptr)
@ stub _mbsncpy_s
@ stub _mbsncpy_s_l
@ cdecl _mbsnextc(str)
......
......@@ -828,7 +828,7 @@
@ stub _mbsncoll(str str long)
@ stub _mbsncoll_l
@ cdecl _mbsncpy(ptr str long)
@ stub _mbsncpy_l
@ cdecl _mbsncpy_l(ptr str long ptr)
@ stub _mbsncpy_s
@ stub _mbsncpy_s_l
@ cdecl _mbsnextc(str)
......
......@@ -806,7 +806,7 @@
@ stub _mbsncoll(str str long)
@ stub _mbsncoll_l
@ cdecl _mbsncpy(ptr str long)
@ stub _mbsncpy_l
@ cdecl _mbsncpy_l(ptr str long ptr)
@ stub _mbsncpy_s
@ stub _mbsncpy_s_l
@ cdecl _mbsnextc(str)
......
......@@ -839,47 +839,66 @@ int CDECL _mbccpy_s(unsigned char* dest, size_t maxsize,
return _mbccpy_s_l(dest, maxsize, copied, src, NULL);
}
/*********************************************************************
* _mbsncpy(MSVCRT.@)
* _mbsncpy_l(MSVCRT.@)
* REMARKS
* The parameter n is the number or characters to copy, not the size of
* the buffer. Use _mbsnbcpy for a function analogical to strncpy
* the buffer. Use _mbsnbcpy_l for a function analogical to strncpy
*/
unsigned char* CDECL _mbsncpy(unsigned char* dst, const unsigned char* src, size_t n)
unsigned char* CDECL _mbsncpy_l(unsigned char* dst, const unsigned char* src, size_t n, _locale_t locale)
{
unsigned char* ret = dst;
if(!n)
return dst;
if (get_mbcinfo()->ismbcodepage)
{
while (*src && n)
unsigned char* ret = dst;
pthreadmbcinfo mbcinfo;
if (!n)
return dst;
if (!MSVCRT_CHECK_PMT(dst && src))
return NULL;
if (locale)
mbcinfo = locale->mbcinfo;
else
mbcinfo = get_mbcinfo();
if (mbcinfo->ismbcodepage)
{
n--;
if (_ismbblead(*src))
{
if (!*(src+1))
while (*src && n)
{
*dst++ = 0;
*dst++ = 0;
break;
n--;
if (_ismbblead_l(*src, locale))
{
if (!*(src + 1))
{
*dst++ = 0;
*dst++ = 0;
break;
}
*dst++ = *src++;
}
*dst++ = *src++;
}
*dst++ = *src++;
}
*dst++ = *src++;
}
}
else
{
while (n)
else
{
n--;
if (!(*dst++ = *src++)) break;
while (n)
{
n--;
if (!(*dst++ = *src++)) break;
}
}
}
while (n--) *dst++ = 0;
return ret;
while (n--) *dst++ = 0;
return ret;
}
/*********************************************************************
* _mbsncpy(MSVCRT.@)
* REMARKS
* The parameter n is the number or characters to copy, not the size of
* the buffer. Use _mbsnbcpy for a function analogical to strncpy
*/
unsigned char* CDECL _mbsncpy(unsigned char* dst, const unsigned char* src, size_t n)
{
return _mbsncpy_l(dst, src, n, NULL);
}
/*********************************************************************
......
......@@ -777,7 +777,7 @@
@ stub _mbsncoll(str str long)
# stub _mbsncoll_l(str str long ptr)
@ cdecl _mbsncpy(ptr str long)
# stub _mbsncpy_l(ptr str long ptr)
@ cdecl _mbsncpy_l(ptr str long ptr)
# stub _mbsncpy_s(ptr long str long)
# stub _mbsncpy_s_l(ptr long str long ptr)
@ cdecl _mbsnextc(str)
......
......@@ -264,6 +264,7 @@ static void test_mbcp(void)
unsigned char *mbstring2 = (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
unsigned char *mbsonlylead = (unsigned char *)"\xb0\0\xb1\xb2 \xb3";
unsigned char buf[16];
unsigned char *ret;
int step;
CPINFO cp_info;
......@@ -462,6 +463,53 @@ static void test_mbcp(void)
expect_bin(buf, "\x00\xff", 2);
}
errno = 0xdeadbeef;
ret = _mbsncpy(NULL, mbstring, 1);
ok(ret == NULL, "_mbsncpy returned %p, expected NULL\n", ret);
ok(errno == EINVAL, "_mbsncpy returned %d\n", errno);
memset(buf, 0xff, sizeof(buf));
errno = 0xdeadbeef;
ret = _mbsncpy(buf, NULL, 1);
ok(ret == NULL, "_mbsncpy returned %p, expected NULL\n", ret);
ok(errno == EINVAL, "_mbsncpy returned %d\n", errno);
expect_bin(buf, "\xff\xff\xff", 3);
errno = 0xdeadbeef;
ret = _mbsncpy(NULL, mbstring, 0);
ok(ret == NULL, "_mbsncpy returned %p, expected NULL\n", ret);
ok(errno == 0xdeadbeef, "_mbsncpy should not change errno\n");
memset(buf, 0xff, sizeof(buf));
errno = 0xdeadbeef;
ret = _mbsncpy(buf, NULL, 0);
ok(ret == buf, "_mbsncpy returned %p, expected %sp\n", ret, buf);
ok(errno == 0xdeadbeef, "_mbsncpy should not change errno\n");
memset(buf, 0xff, sizeof(buf));
errno = 0xdeadbeef;
ret = _mbsncpy(NULL, mbstring, 1);
ok(ret == NULL, "_mbsncpy returned %p, expected NULL\n", ret);
ok(errno == EINVAL, "_mbsncpy returned %d\n", errno);
memset(buf, 0xff, sizeof(buf));
errno = 0xdeadbeef;
ret = _mbsncpy(buf, NULL, 1);
ok(ret == NULL, "_mbsncpy returned %p, expected NULL\n", ret);
ok(errno == EINVAL, "_mbsncpy returned %d\n", errno);
memset(buf, 0xff, sizeof(buf));
ret = _mbsncpy(NULL, mbstring, 0);
ok(ret == NULL, "_mbsncpy returned %p, expected %p\n", ret, buf);
memset(buf, 0xff, sizeof(buf));
ret = _mbsncpy(buf, NULL, 0);
ok(ret == buf, "_mbsncpy returned %p, expected %sp\n", ret, buf);
memset(buf, 0xff, sizeof(buf));
ret = _mbsncpy(buf, mbstring, 0);
ok(ret == buf, "_mbsncpy returned %p, expected %p\n", ret, buf);
memset(buf, 0xff, sizeof(buf));
_mbsncpy(buf, mbstring, 1);
expect_bin(buf, "\xb0\xb1\xff", 3);
......
......@@ -672,7 +672,7 @@
@ stub _mbsncoll(str str long)
@ stub _mbsncoll_l
@ cdecl _mbsncpy(ptr str long)
@ stub _mbsncpy_l
@ cdecl _mbsncpy_l(ptr str long ptr)
@ stub _mbsncpy_s
@ stub _mbsncpy_s_l
@ cdecl _mbsnextc(str)
......@@ -1241,7 +1241,7 @@
@ stub _o__mbsncoll
@ stub _o__mbsncoll_l
@ cdecl _o__mbsncpy(ptr str long) _mbsncpy
@ stub _o__mbsncpy_l
@ cdecl _o__mbsncpy_l(ptr str long ptr) _mbsncpy_l
@ stub _o__mbsncpy_s
@ stub _o__mbsncpy_s_l
@ cdecl _o__mbsnextc(str) _mbsnextc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment