mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-15 21:57:17 +00:00
ntdll: Add strncpy_s and wcsncpy_s.
Implementation copied from msvcrt. Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
83cd792e35
commit
94e960c861
|
@ -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)
|
||||
|
|
|
@ -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.@)
|
||||
*/
|
||||
|
|
|
@ -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.@)
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue