Commit b39c59e7 authored by Damjan Jovanovic's avatar Damjan Jovanovic Committed by Alexandre Julliard

msvcrt: Improve wcsncat_s.

parent c7536ef8
......@@ -1459,8 +1459,13 @@ static void test_wcsncat_s(void)
dst[0] = 0;
ret = p_wcsncat_s(dst, 2, src, _TRUNCATE);
todo_wine ok(ret == 80, "err = %d\n", ret);
ok(ret == STRUNCATE, "err = %d\n", ret);
ok(dst[0] == 'a' && dst[1] == 0, "dst is %s\n", wine_dbgstr_w(dst));
memcpy(dst, abcW, sizeof(abcW));
dst[3] = 'd';
ret = p_wcsncat_s(dst, 4, src, 4);
ok(ret == EINVAL, "err = %d\n", ret);
}
START_TEST(string)
......
......@@ -1588,8 +1588,8 @@ INT CDECL MSVCRT_wcsncat_s(MSVCRT_wchar_t *dst, MSVCRT_size_t elem,
const MSVCRT_wchar_t *src, MSVCRT_size_t count)
{
MSVCRT_size_t srclen;
MSVCRT_size_t i;
MSVCRT_wchar_t dststart;
INT ret = 0;
if (src == NULL && count > 0)
return MSVCRT_EINVAL;
......@@ -1597,34 +1597,33 @@ INT CDECL MSVCRT_wcsncat_s(MSVCRT_wchar_t *dst, MSVCRT_size_t elem,
return MSVCRT_EINVAL;
if (elem == 0)
return MSVCRT_EINVAL;
if (count == 0)
return 0;
for (i = 0; i < elem; i++)
for (dststart = 0; dststart < elem; dststart++)
{
dststart = i;
if (dst[i] == '\0')
if (dst[dststart] == '\0')
break;
}
if (dststart == elem)
return MSVCRT_EINVAL;
if (count == MSVCRT__TRUNCATE)
srclen = elem - dststart - 1;
else
srclen = count;
for (i = 0; i < srclen; i++)
{
if (src[i] == '\0')
srclen = strlenW(src);
if (srclen >= (elem - dststart))
{
srclen = i;
break;
srclen = elem - dststart - 1;
ret = MSVCRT_STRUNCATE;
}
}
else
srclen = min(strlenW(src), count);
if (srclen < (elem - dststart))
{
memcpy(&dst[dststart], src, srclen*sizeof(MSVCRT_wchar_t));
dst[srclen] = '\0';
return 0;
return ret;
}
dst[0] = '\0';
return MSVCRT_ERANGE;
......
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