Commit c7aba973 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Added strnlen implementation.

parent bf128642
...@@ -1389,7 +1389,7 @@ ...@@ -1389,7 +1389,7 @@
@ cdecl strncmp(str str long) msvcrt.strncmp @ cdecl strncmp(str str long) msvcrt.strncmp
@ cdecl strncpy(ptr str long) msvcrt.strncpy @ cdecl strncpy(ptr str long) msvcrt.strncpy
@ stub strncpy_s @ stub strncpy_s
@ stub strnlen @ cdecl strnlen(str long) msvcrt.strnlen
@ cdecl strpbrk(str str) msvcrt.strpbrk @ cdecl strpbrk(str str) msvcrt.strpbrk
@ cdecl strrchr(str long) msvcrt.strrchr @ cdecl strrchr(str long) msvcrt.strrchr
@ cdecl strspn(str str) msvcrt.strspn @ cdecl strspn(str str) msvcrt.strspn
......
...@@ -1373,7 +1373,7 @@ ...@@ -1373,7 +1373,7 @@
@ cdecl strncmp(str str long) msvcrt.strncmp @ cdecl strncmp(str str long) msvcrt.strncmp
@ cdecl strncpy(ptr str long) msvcrt.strncpy @ cdecl strncpy(ptr str long) msvcrt.strncpy
@ stub strncpy_s @ stub strncpy_s
@ stub strnlen @ cdecl strnlen(str long) msvcrt.strnlen
@ cdecl strpbrk(str str) msvcrt.strpbrk @ cdecl strpbrk(str str) msvcrt.strpbrk
@ cdecl strrchr(str long) msvcrt.strrchr @ cdecl strrchr(str long) msvcrt.strrchr
@ cdecl strspn(str str) msvcrt.strspn @ cdecl strspn(str str) msvcrt.strspn
......
...@@ -1327,7 +1327,7 @@ ...@@ -1327,7 +1327,7 @@
@ cdecl strncmp(str str long) ntdll.strncmp @ cdecl strncmp(str str long) ntdll.strncmp
@ cdecl strncpy(ptr str long) ntdll.strncpy @ cdecl strncpy(ptr str long) ntdll.strncpy
# stub strncpy_s # stub strncpy_s
# stub strnlen @ cdecl strnlen(str long) MSVCRT_strnlen
@ cdecl strpbrk(str str) ntdll.strpbrk @ cdecl strpbrk(str str) ntdll.strpbrk
@ cdecl strrchr(str long) ntdll.strrchr @ cdecl strrchr(str long) ntdll.strrchr
@ cdecl strspn(str str) ntdll.strspn @ cdecl strspn(str str) ntdll.strspn
......
...@@ -314,3 +314,16 @@ MSVCRT_ulong CDECL MSVCRT_strtoul(const char* nptr, char** end, int base) ...@@ -314,3 +314,16 @@ MSVCRT_ulong CDECL MSVCRT_strtoul(const char* nptr, char** end, int base)
return ret; return ret;
} }
/******************************************************************
* strnlen (MSVCRT.@)
*/
MSVCRT_size_t CDECL MSVCRT_strnlen(const char *s, MSVCRT_size_t maxlen)
{
MSVCRT_size_t i;
for(i=0; i<maxlen; i++)
if(!s[i]) break;
return i;
}
...@@ -52,6 +52,7 @@ static int (__cdecl *pstrcat_s)(char *dst, size_t len, const char *src); ...@@ -52,6 +52,7 @@ static int (__cdecl *pstrcat_s)(char *dst, size_t len, const char *src);
static int (__cdecl *p_mbsnbcpy_s)(unsigned char * dst, size_t size, const unsigned char * src, size_t count); static int (__cdecl *p_mbsnbcpy_s)(unsigned char * dst, size_t size, const unsigned char * src, size_t count);
static int (__cdecl *p_wcscpy_s)(wchar_t *wcDest, size_t size, const wchar_t *wcSrc); static int (__cdecl *p_wcscpy_s)(wchar_t *wcDest, size_t size, const wchar_t *wcSrc);
static int (__cdecl *p_wcsupr_s)(wchar_t *str, size_t size); static int (__cdecl *p_wcsupr_s)(wchar_t *str, size_t size);
static size_t (__cdecl *p_strnlen)(const char *, size_t);
static int *p__mb_cur_max; static int *p__mb_cur_max;
static unsigned char *p_mbctype; static unsigned char *p_mbctype;
...@@ -911,6 +912,26 @@ static void test_strtol(void) ...@@ -911,6 +912,26 @@ static void test_strtol(void)
ok(errno == ERANGE, "wrong errno %d\n", errno); ok(errno == ERANGE, "wrong errno %d\n", errno);
} }
static void test_strnlen(void)
{
static const char str[] = "string";
size_t res;
if(!p_strnlen) {
win_skip("strnlen not found\n");
return;
}
res = p_strnlen(str, 20);
ok(res == 6, "Returned length = %d\n", (int)res);
res = p_strnlen(str, 3);
ok(res == 3, "Returned length = %d\n", (int)res);
res = p_strnlen(NULL, 0);
ok(res == 0, "Returned length = %d\n", (int)res);
}
START_TEST(string) START_TEST(string)
{ {
char mem[100]; char mem[100];
...@@ -930,6 +951,7 @@ START_TEST(string) ...@@ -930,6 +951,7 @@ START_TEST(string)
p_mbsnbcpy_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcpy_s" ); p_mbsnbcpy_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcpy_s" );
p_wcscpy_s = (void *)GetProcAddress( hMsvcrt,"wcscpy_s" ); p_wcscpy_s = (void *)GetProcAddress( hMsvcrt,"wcscpy_s" );
p_wcsupr_s = (void *)GetProcAddress( hMsvcrt,"_wcsupr_s" ); p_wcsupr_s = (void *)GetProcAddress( hMsvcrt,"_wcsupr_s" );
p_strnlen = (void *)GetProcAddress( hMsvcrt,"strnlen" );
/* MSVCRT memcpy behaves like memmove for overlapping moves, /* MSVCRT memcpy behaves like memmove for overlapping moves,
MFC42 CString::Insert seems to rely on that behaviour */ MFC42 CString::Insert seems to rely on that behaviour */
...@@ -959,4 +981,5 @@ START_TEST(string) ...@@ -959,4 +981,5 @@ START_TEST(string)
test_wcscpy_s(); test_wcscpy_s();
test__wcsupr_s(); test__wcsupr_s();
test_strtol(); test_strtol();
test_strnlen();
} }
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