Piotr Caban : msvcrt: Added support for _TRUNCATE flag in wcsncpy_s.
Alexandre Julliard
julliard at winehq.org
Thu Apr 12 15:23:12 CDT 2012
Module: wine
Branch: master
Commit: a80aec4c56bfc9b845e89bf55af4e638f153b4cd
URL: http://source.winehq.org/git/wine.git/?a=commit;h=a80aec4c56bfc9b845e89bf55af4e638f153b4cd
Author: Piotr Caban <piotr at codeweavers.com>
Date: Thu Apr 12 16:19:31 2012 +0200
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 9f0d8be..afa9954 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 b6786ce..21cee47 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;
}
/******************************************************************
More information about the wine-cvs
mailing list