Alistair Leslie-Hughes : msvcrt: Implement wcscpy_s.

Alexandre Julliard julliard at winehq.org
Wed Feb 27 08:03:28 CST 2008


Module: wine
Branch: master
Commit: 00609d5e7824a117084f3f4b75e1aec03b60102a
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=00609d5e7824a117084f3f4b75e1aec03b60102a

Author: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
Date:   Wed Feb 27 19:58:04 2008 +1100

msvcrt: Implement wcscpy_s.

---

 dlls/msvcrt/msvcrt.spec    |    1 +
 dlls/msvcrt/tests/string.c |   45 ++++++++++++++++++++++++++++++++++++++++++++
 dlls/msvcrt/wcs.c          |   38 +++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec
index d6cffcb..7b821e6 100644
--- a/dlls/msvcrt/msvcrt.spec
+++ b/dlls/msvcrt/msvcrt.spec
@@ -761,6 +761,7 @@
 @ cdecl wcscmp(wstr wstr) ntdll.wcscmp
 @ cdecl wcscoll(wstr wstr) MSVCRT_wcscoll
 @ cdecl wcscpy(ptr wstr) ntdll.wcscpy
+@ cdecl wcscpy_s(ptr long wstr) MSVCRT_wcscpy_s
 @ cdecl wcscspn(wstr wstr) ntdll.wcscspn
 @ cdecl wcsftime(ptr long wstr ptr) MSVCRT_wcsftime
 @ cdecl wcslen(wstr) ntdll.wcslen
diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c
index c6dcd34..4201c5e 100644
--- a/dlls/msvcrt/tests/string.c
+++ b/dlls/msvcrt/tests/string.c
@@ -50,6 +50,7 @@ static int* (*pmemcmp)(void *, const void *, size_t n);
 static int (*pstrcpy_s)(char *dst, size_t len, const char *src);
 static int (*pstrcat_s)(char *dst, size_t len, const char *src);
 static int (*p_mbsnbcpy_s)(unsigned char * dst, size_t size, const unsigned char * src, size_t count);
+static int (*p_wcscpy_s)(wchar_t *wcDest, size_t size, const wchar_t *wcSrc);
 
 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
@@ -562,6 +563,47 @@ static void test__mbsnbcpy_s(void)
        dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
 }
 
+static void test_wcscpy_s(void)
+{
+    static const WCHAR szLongText[] = { 'T','h','i','s','A','L','o','n','g','s','t','r','i','n','g',0 };
+    static WCHAR szDest[18];
+    static WCHAR szDestShort[8];
+    int ret;
+
+    if(!p_wcscpy_s)
+    {
+        skip("wcscpy_s not found\n");
+        return;
+    }
+
+    /* Test NULl Dest */
+    ret = p_wcscpy_s(NULL, 18, szLongText);
+    ok(ret == EINVAL, "p_wcscpy_s expect EINVAL got %d\n", ret);
+
+    /* Test NULl Source */
+    szDest[0] = 'A';
+    ret = p_wcscpy_s(szDest, 18, NULL);
+    ok(ret == EINVAL, "expected EINVAL got %d\n", ret);
+    ok(szDest[0] == 0, "szDest[0] not 0\n");
+
+    /* Test invalid size */
+    szDest[0] = 'A';
+    ret = p_wcscpy_s(szDest, 0, szLongText);
+    ok(ret == ERANGE, "expected ERANGE got %d\n", ret);
+    ok(szDest[0] == 0, "szDest[0] not 0\n");
+
+    /* Copy same buffer size */
+    ret = p_wcscpy_s(szDest, 18, szLongText);
+    ok(ret == 0, "expected 0 got %d\n", ret);
+    ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
+
+    /* Copy smaller buffer size */
+    szDest[0] = 'A';
+    ret = p_wcscpy_s(szDestShort, 8, szLongText);
+    ok(ret == EINVAL, "expected EINVAL got %d\n", ret);
+    ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
+}
+
 START_TEST(string)
 {
     char mem[100];
@@ -577,6 +619,7 @@ START_TEST(string)
     SET(pstrcpy_s,"strcpy_s");
     SET(pstrcat_s,"strcat_s");
     SET(p_mbsnbcpy_s,"_mbsnbcpy_s");
+    SET(p_wcscpy_s,"wcscpy_s");
 
     /* MSVCRT memcpy behaves like memmove for overlapping moves,
        MFC42 CString::Insert seems to rely on that behaviour */
@@ -599,4 +642,6 @@ START_TEST(string)
     test_strcpy_s();
     test_strcat_s();
     test__mbsnbcpy_s();
+
+    test_wcscpy_s();
 }
diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c
index 92dd644..c6f3e95 100644
--- a/dlls/msvcrt/wcs.c
+++ b/dlls/msvcrt/wcs.c
@@ -971,3 +971,41 @@ INT CDECL MSVCRT_iswxdigit( MSVCRT_wchar_t wc )
 {
     return isxdigitW( wc );
 }
+
+/*********************************************************************
+ *		wcscpy_s (MSVCRT.@)
+ */
+INT CDECL MSVCRT_wcscpy_s( MSVCRT_wchar_t* wcDest, MSVCRT_size_t numElement, const  MSVCRT_wchar_t *wcSrc)
+{
+    INT size = 0;
+
+    if(!wcDest)
+        return MSVCRT_EINVAL;
+
+    if(!wcSrc)
+    {
+        wcDest[0] = 0;
+        return MSVCRT_EINVAL;
+    }
+
+    if(numElement == 0)
+    {
+        wcDest[0] = 0;
+        return MSVCRT_ERANGE;
+    }
+
+    size = strlenW(wcSrc) + 1;
+
+    if(size > numElement)
+    {
+        wcDest[0] = 0;
+        return MSVCRT_EINVAL;
+    }
+
+    if(size > numElement)
+        size = numElement;
+
+    memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
+
+    return 0;
+}




More information about the wine-cvs mailing list