Locale-Sensitive C/C++ String Operation Function
char *strncpy(char *strDestination, const char *strSource, size_t count);
wchar_t *wcsncpy(wchar_t *strDestination, const wchar_t *strSource, size_t count);
unsigned char *_mbsncpy(unsigned char *strDestination, const unsigned char *strSource, size_t count);
_TXCHAR *_tcsnccpy(_TXCHAR *strDestination, const _TXCHAR *strSource, size_t count);
unsigned char *_mbsnbcpy(unsigned char *strDestination, const unsigned char *strSource, size_t count);
_TXCHAR *_tcsncpy(_TXCHAR *strDestination, const _TXCHAR *strSource, size_t count);
Internationalization (I18n) Function Overview
The strncpy function copies at most, the first count single-byte characters of strSource to strDestination .
The strSource and strDestination arrays cannot overlap.
The caller must ensure strDestination points to a region of memory that is large enough to hold
the result, including the null terminator.
wcsncpy is the wide version of the function; its parameters and return are wide character strings.
Supported on Windows platforms only, _mbsncpy and _mbsnbcpy are multibyte versions of strncpy .
_mbsncpy will copy at most count multibyte characters and
_mbsnbcpy will copy at most count bytes.
They both use the current multibyte code page.
_tcsnccpy and _tcsncpy are the corresponding Generic functions
for _mbsncpy and _mbsnbcpy , respectively.
I18n Issues
Use the appropriate version of the function as required for internationalization support, noting the following:
Since there is no multibyte-character version of strncpy on ANSI platforms, the count argument
of a UTF-8 string will need to be the number of bytes rather than the number of multibyte characters.
Since multibyte strings terminate in a null byte terminator, strncpy works with multibyte strings, as long as count is set correctly.
For Windows MBCS platforms, ensure that the multibyte code page is set properly, as _mbsncpy and _mbsnbcpy depend on it. By default, the multibyte code page is set to the system-default ANSI code page obtained from the operating system at program startup. Use _getmbcp and _setmbcp to query or change the current multibyte code page, respectively.
Recommended Replacements*
On Windows platforms, a more secure string function is recommended.
However, there are differences in the handling of multibyte-character strings which will need to be
considered before switching. For more details, click on one of the secure
functions in the following table: they are listed as the first choices for the Windows rulesets.
*If you're already using the recommended function, see I18n Issues for other reasons why Globalyzer is detecting the function.
Locale-Sensitive C/C++
String Operation Functions
|