ntdll: Add strncat_s and wcsncat_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:55 +02:00
parent 94e960c861
commit 7c70b9397f
3 changed files with 84 additions and 0 deletions

View file

@ -1595,6 +1595,7 @@
@ cdecl strcspn(str str)
@ cdecl strlen(str)
@ cdecl strncat(str str long)
@ cdecl strncat_s(str long str long)
@ cdecl strncmp(str str long)
@ cdecl strncpy(ptr str long)
@ cdecl strncpy_s(ptr long str long)
@ -1626,6 +1627,7 @@
@ cdecl wcscspn(wstr wstr)
@ cdecl wcslen(wstr)
@ cdecl wcsncat(wstr wstr long)
@ cdecl wcsncat_s(wstr long wstr long)
@ cdecl wcsncmp(wstr wstr long)
@ cdecl wcsncpy(ptr wstr long)
@ cdecl wcsncpy_s(ptr long wstr long)

View file

@ -332,6 +332,47 @@ char * __cdecl strncat( char *dst, const char *src, size_t len )
}
/*********************************************************************
* strncat_s (NTDLL.@)
*/
errno_t __cdecl strncat_s( char *dst, size_t len, const char *src, size_t count )
{
size_t i, j;
if (!dst || !len) return EINVAL;
if (!count) return 0;
if (!src)
{
*dst = 0;
return EINVAL;
}
for (i = 0; i < len; i++) if (!dst[i]) break;
if (i == len)
{
*dst = 0;
return EINVAL;
}
for (j = 0; (j + i) < len; j++)
{
if (count == _TRUNCATE && j + i == len - 1)
{
dst[j + i] = 0;
return STRUNCATE;
}
if (j == count || !(dst[j + i] = src[j]))
{
dst[j + i] = 0;
return 0;
}
}
*dst = 0;
return ERANGE;
}
/*********************************************************************
* strncmp (NTDLL.@)
*/

View file

@ -268,6 +268,47 @@ LPWSTR __cdecl wcsncat( LPWSTR s1, LPCWSTR s2, size_t n )
}
/*********************************************************************
* wcsncat_s (NTDLL.@)
*/
errno_t __cdecl wcsncat_s( wchar_t *dst, size_t len, const wchar_t *src, size_t count )
{
size_t i, j;
if (!dst || !len) return EINVAL;
if (!count) return 0;
if (!src)
{
*dst = 0;
return EINVAL;
}
for (i = 0; i < len; i++) if (!dst[i]) break;
if (i == len)
{
*dst = 0;
return EINVAL;
}
for (j = 0; (j + i) < len; j++)
{
if (count == _TRUNCATE && j + i == len - 1)
{
dst[j + i] = 0;
return STRUNCATE;
}
if (j == count || !(dst[j + i] = src[j]))
{
dst[j + i] = 0;
return 0;
}
}
*dst = 0;
return ERANGE;
}
/*********************************************************************
* wcsncmp (NTDLL.@)
*/