Internationalization and localization tools


Locale-Sensitive Length Function

char *strncat(char *strDestination, const char *strSource, size_t count);

wchar_t *wcsncat(wchar_t *strDestination, const wchar_t *strSource, size_t count);

unsigned char *_mbsncat(unsigned char *strDestination, const unsigned char *strSource, size_t count);

_TXCHAR *_tcsnccat(_TXCHAR *strDestination, const _TXCHAR *strSource, size_t count);

unsigned char *_mbsnbcat(unsigned char *strDestination, const unsigned char *strSource, size_t count);

_TXCHAR *_tcsncat(_TXCHAR *strDestination, const _TXCHAR *strSource, size_t count);

Internationalization (I18n) Function Overview

The strncat function concatenates at most, the first count single-byte characters of strSource onto the end of strDestination, overwriting the null byte at the end of 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 concatenated result, including the null terminator.

wcsncat is the wide version of the function; its parameters and return are wide character strings.

Supported on Windows platforms only, _mbsncat and _mbsnbcat are multibyte versions of strncat. _mbsncat will append at most count multibyte characters and _mbsnbcat will append at most count bytes. They both use the current multibyte code page.

_tcsnccat and _tcsncat are the corresponding Generic functions for _mbsncat and _mbsnbcat, respectively.

I18n Issues

Special care must be taken with the count parameter. See Locale-Sensitive Length Functions for a complete discussion of the issues involved with functions that pass length parameters.

There is no multibyte-character version of strncat on ANSI platforms. However, for ANSI UTF-8 the count argument of a UTF-8 string can be set to the number of bytes rather than the number of multibyte characters to be concatenated. (Since multibyte UTF-8 strings are terminated with a single null byte character, strncat will actually work with multibyte strings as long as count is set to the number of bytes instead of characters).

For Windows MBCS platforms, ensure that the multibyte code page is set properly, as _mbsncat and _mbsnbcat 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 Length Functions

 

Lingoport internationalization and localization services and software