From a80aec4c56bfc9b845e89bf55af4e638f153b4cd Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Thu, 12 Apr 2012 16:19:31 +0200 Subject: [PATCH] msvcrt: Added support for _TRUNCATE flag in wcsncpy_s. --- dlls/msvcrt/tests/string.c | 6 ++++++ dlls/msvcrt/wcs.c | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c index 9f0d8be085..afa995419e 100644 --- a/dlls/msvcrt/tests/string.c +++ b/dlls/msvcrt/tests/string.c @@ -682,6 +682,12 @@ static void test_wcscpy_s(void) ret = p_wcsncpy_s(szDestShort, 8, szLongText, sizeof(szLongText)/sizeof(WCHAR)); ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret); ok(szDestShort[0] == 0, "szDestShort[0] not 0\n"); + + szDest[0] = 'A'; + ret = p_wcsncpy_s(szDest, 5, szLongText, -1); + ok(ret == STRUNCATE, "expected STRUNCATE got %d\n", ret); + ok(szDest[4] == 0, "szDest[4] not 0\n"); + ok(!memcmp(szDest, szLongText, 4*sizeof(WCHAR)), "szDest = %s\n", wine_dbgstr_w(szDest)); } static void test__wcsupr_s(void) diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c index b6786cef42..21cee473a5 100644 --- a/dlls/msvcrt/wcs.c +++ b/dlls/msvcrt/wcs.c @@ -1230,6 +1230,7 @@ INT CDECL MSVCRT_wcsncpy_s( MSVCRT_wchar_t* wcDest, MSVCRT_size_t numElement, co MSVCRT_size_t count ) { MSVCRT_size_t size = 0; + INT ret = 0; if (!wcDest || !numElement) return MSVCRT_EINVAL; @@ -1242,8 +1243,12 @@ INT CDECL MSVCRT_wcsncpy_s( MSVCRT_wchar_t* wcDest, MSVCRT_size_t numElement, co } size = min(strlenW(wcSrc), count); - - if (size >= numElement) + if (count==MSVCRT__TRUNCATE && size>=numElement) + { + ret = MSVCRT_STRUNCATE; + size = numElement-1; + } + else if (size >= numElement) { return MSVCRT_ERANGE; } @@ -1251,7 +1256,7 @@ INT CDECL MSVCRT_wcsncpy_s( MSVCRT_wchar_t* wcDest, MSVCRT_size_t numElement, co memcpy( wcDest, wcSrc, size*sizeof(WCHAR) ); wcDest[size] = '\0'; - return 0; + return ret; } /******************************************************************