diff --git a/dlls/msvcrt/string.c b/dlls/msvcrt/string.c index c5d0e18d501..082029dae6c 100644 --- a/dlls/msvcrt/string.c +++ b/dlls/msvcrt/string.c @@ -581,6 +581,8 @@ char* __cdecl MSVCRT_strncpy(char *dst, const char *src, MSVCRT_size_t len) for(i=0; i TEST_STRNCPY_LEN */ + ret = strncpy(dst, "01234567890123456789", TEST_STRNCPY_LEN); + ok(ret == dst, "ret != dst\n"); + ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n"); + + /* without null-terminated */ + ret = strncpy(dst, not_null_terminated, TEST_STRNCPY_LEN); + ok(ret == dst, "ret != dst\n"); + ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n"); + + /* strlen(src) < TEST_STRNCPY_LEN */ + strcpy(dst, "0123456789"); + ret = strncpy(dst, "012345", TEST_STRNCPY_LEN); + ok(ret == dst, "ret != dst\n"); + ok(!strcmp(dst, "012345"), "dst != 012345\n"); + ok(dst[TEST_STRNCPY_LEN - 1] == '\0', "dst[TEST_STRNCPY_LEN - 1] != 0\n"); + + /* strlen(src) == TEST_STRNCPY_LEN */ + ret = strncpy(dst, "0123456789", TEST_STRNCPY_LEN); + ok(ret == dst, "ret != dst\n"); + ok(!strncmp(dst, "0123456789", TEST_STRNCPY_LEN), "dst != 0123456789\n"); +} + START_TEST(string) { char mem[100]; @@ -2675,4 +2705,5 @@ START_TEST(string) test__stricmp(); test__wcstoi64(); test_atoi(); + test_strncpy(); }