ntdll: Add strncpy_s and wcsncpy_s.

Implementation copied from msvcrt.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2022-06-29 11:49:38 +02:00
parent 83cd792e35
commit 94e960c861
3 changed files with 86 additions and 0 deletions

View file

@ -1597,6 +1597,7 @@
@ cdecl strncat(str str long)
@ cdecl strncmp(str str long)
@ cdecl strncpy(ptr str long)
@ cdecl strncpy_s(ptr long str long)
@ cdecl strnlen(ptr long)
@ cdecl strpbrk(str str)
@ cdecl strrchr(str long)
@ -1627,6 +1628,7 @@
@ cdecl wcsncat(wstr wstr long)
@ cdecl wcsncmp(wstr wstr long)
@ cdecl wcsncpy(ptr wstr long)
@ cdecl wcsncpy_s(ptr long wstr long)
@ cdecl wcsnlen(ptr long)
@ cdecl wcspbrk(wstr wstr)
@ cdecl wcsrchr(wstr long)

View file

@ -356,6 +356,48 @@ char * __cdecl strncpy( char *dst, const char *src, size_t len )
}
/*********************************************************************
* strncpy_s (NTDLL.@)
*/
errno_t __cdecl strncpy_s( char *dst, size_t len, const char *src, size_t count )
{
size_t i, end;
if (!count)
{
if (dst && len) *dst = 0;
return 0;
}
if (!dst || !len) return EINVAL;
if (!src)
{
*dst = 0;
return EINVAL;
}
if (count != _TRUNCATE && count < len)
end = count;
else
end = len - 1;
for (i = 0; i < end; i++)
if (!(dst[i] = src[i])) return 0;
if (count == _TRUNCATE)
{
dst[i] = 0;
return STRUNCATE;
}
if (end == count)
{
dst[i] = 0;
return 0;
}
dst[0] = 0;
return ERANGE;
}
/*********************************************************************
* strnlen (NTDLL.@)
*/

View file

@ -292,6 +292,48 @@ LPWSTR __cdecl wcsncpy( LPWSTR s1, LPCWSTR s2, size_t n )
}
/*********************************************************************
* wcsncpy_s (NTDLL.@)
*/
errno_t __cdecl wcsncpy_s( wchar_t *dst, size_t len, const wchar_t *src, size_t count )
{
size_t i, end;
if (!count)
{
if (dst && len) *dst = 0;
return 0;
}
if (!dst || !len) return EINVAL;
if (!src)
{
*dst = 0;
return EINVAL;
}
if (count != _TRUNCATE && count < len)
end = count;
else
end = len - 1;
for (i = 0; i < end; i++)
if (!(dst[i] = src[i])) return 0;
if (count == _TRUNCATE)
{
dst[i] = 0;
return STRUNCATE;
}
if (end == count)
{
dst[i] = 0;
return 0;
}
dst[0] = 0;
return ERANGE;
}
/*********************************************************************
* wcsnlen (NTDLL.@)
*/