Files
reactos/sdk/lib/ucrt/string/strncpy.c
Katayama Hirofumi MZ 300e1d525d [MSVCRT][CRT][UCRT] Disable intrinsic string functions on MSVC (#9157)
VS2022 version 17.2 and later (`_MSC_VER >= 1932`) added new intrinsic
functions (`strncmp`, `strncpy`, `wcsncmp`, and `wcsncpy`).
As we implement these ourselves, we have to avoid compiler error C2169.

This problem surfaced with a recent GitHub Actions update:
https://github.com/actions/runner-images/issues/14017

Use `#pragma function(...)` to disable new intrinsic functions.
2026-06-13 18:10:15 +03:00

57 lines
1.5 KiB
C

/***
*strncpy.c - copy at most n characters of string
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* defines strncpy() - copy at most n characters of string
*
*******************************************************************************/
#include <string.h>
#if defined(_MSC_VER) && (defined(_M_ARM) || _MSC_VER >= 1932) // VS2022 version 17.2 and later
#pragma function(strncpy)
#endif
/***
*char *strncpy(dest, source, count) - copy at most n characters
*
*Purpose:
* Copies count characters from the source string to the
* destination. If count is less than the length of source,
* NO NULL CHARACTER is put onto the end of the copied string.
* If count is greater than the length of sources, dest is padded
* with null characters to length count.
*
*
*Entry:
* char *dest - pointer to destination
* char *source - source string for copy
* unsigned count - max number of characters to copy
*
*Exit:
* returns dest
*
*Exceptions:
*
*******************************************************************************/
char * __cdecl strncpy (
char * dest,
const char * source,
size_t count
)
{
char *start = dest;
while (count && (*dest++ = *source++) != '\0') /* copy string */
count--;
if (count) /* pad out with zeroes */
while (--count)
*dest++ = '\0';
return(start);
}