msvcrt: Move the strncpy_s() implementation to string.c.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2022-06-27 10:48:11 +02:00
parent aa7a4b7803
commit 3514e65f26
2 changed files with 38 additions and 38 deletions

View file

@ -827,44 +827,6 @@ int CDECL wmemcpy_s(wchar_t *dest, size_t numberOfElements,
}
#endif
/*********************************************************************
* strncpy_s (MSVCRT.@)
*/
int CDECL strncpy_s(char *dest, size_t numberOfElements,
const char *src, size_t count)
{
size_t i, end;
TRACE("(%p %Iu %s %Iu)\n", dest, numberOfElements, debugstr_a(src), count);
if(!count) {
if(dest && numberOfElements)
*dest = 0;
return 0;
}
if (!MSVCRT_CHECK_PMT(dest != NULL)) return EINVAL;
if (!MSVCRT_CHECK_PMT(src != NULL)) return EINVAL;
if (!MSVCRT_CHECK_PMT(numberOfElements != 0)) return EINVAL;
if(count!=_TRUNCATE && count<numberOfElements)
end = count;
else
end = numberOfElements-1;
for(i=0; i<end && src[i]; i++)
dest[i] = src[i];
if(!src[i] || end==count || count==_TRUNCATE) {
dest[i] = '\0';
return 0;
}
MSVCRT_INVALID_PMT("dest[numberOfElements] is too small", EINVAL);
dest[0] = '\0';
return EINVAL;
}
BOOL msvcrt_init_heap(void)
{
heap = HeapCreate(0, 0, 0);

View file

@ -1268,6 +1268,44 @@ char* __cdecl strncpy(char *dst, const char *src, size_t len)
return dst;
}
/******************************************************************
* strncpy_s (MSVCRT.@)
*/
int CDECL strncpy_s(char *dest, size_t numberOfElements,
const char *src, size_t count)
{
size_t i, end;
TRACE("(%p %Iu %s %Iu)\n", dest, numberOfElements, debugstr_a(src), count);
if(!count) {
if(dest && numberOfElements)
*dest = 0;
return 0;
}
if (!MSVCRT_CHECK_PMT(dest != NULL)) return EINVAL;
if (!MSVCRT_CHECK_PMT(src != NULL)) return EINVAL;
if (!MSVCRT_CHECK_PMT(numberOfElements != 0)) return EINVAL;
if(count!=_TRUNCATE && count<numberOfElements)
end = count;
else
end = numberOfElements-1;
for(i=0; i<end && src[i]; i++)
dest[i] = src[i];
if(!src[i] || end==count || count==_TRUNCATE) {
dest[i] = '\0';
return 0;
}
MSVCRT_INVALID_PMT("dest[numberOfElements] is too small", EINVAL);
dest[0] = '\0';
return EINVAL;
}
/*********************************************************************
* strcpy (MSVCRT.@)
*/