Commit 3514e65f authored by Alexandre Julliard's avatar Alexandre Julliard

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

parent aa7a4b78
...@@ -827,44 +827,6 @@ int CDECL wmemcpy_s(wchar_t *dest, size_t numberOfElements, ...@@ -827,44 +827,6 @@ int CDECL wmemcpy_s(wchar_t *dest, size_t numberOfElements,
} }
#endif #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) BOOL msvcrt_init_heap(void)
{ {
heap = HeapCreate(0, 0, 0); heap = HeapCreate(0, 0, 0);
......
...@@ -1268,6 +1268,44 @@ char* __cdecl strncpy(char *dst, const char *src, size_t len) ...@@ -1268,6 +1268,44 @@ char* __cdecl strncpy(char *dst, const char *src, size_t len)
return dst; 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.@) * strcpy (MSVCRT.@)
*/ */
......
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