_mbsnbcat_s、_mbsnbcat_s_l_mbsnbcat_s, _mbsnbcat_s_l

将追加到多字节字符字符串,最多,第一个n的另一个多字节字符字符串的字节。Appends to a multibyte character string, at most, the first n bytes of another multibyte-character string. 这些版本的 _mbsnbcat、_mbsnbcat_l 具有安全增强功能,如 CRT 中的安全功能中所述。These are versions of _mbsnbcat, _mbsnbcat_l that have security enhancements, as described in Security Features in the CRT.

重要

此 API 不能用于在 Windows 运行时中执行的应用程序。This API cannot be used in applications that execute in the Windows Runtime. 有关详细信息,请参阅通用 Windows 平台应用中不支持的 CRT 函数For more information, see CRT functions not supported in Universal Windows Platform apps.

语法Syntax

errno_t _mbsnbcat_s(
   unsigned char *dest,
   size_t sizeInBytes,
   const unsigned char *src,
   size_t count
);
errno_t _mbsnbcat_s_l(
   unsigned char *dest,
   size_t sizeInBytes,
   const unsigned char *src,
   size_t count,
   _locale_t locale
);
template <size_t size>
errno_t _mbsnbcat_s(
   unsigned char (&dest)[size],
   const unsigned char *src,
   size_t count
); // C++ only
template <size_t size>
errno_t _mbsnbcat_s_l(
   unsigned char (&dest)[size],
   const unsigned char *src,
   size_t count,
   _locale_t locale
); // C++ only

参数Parameters

destdest
以 null 终止的多字节字符目标字符串。Null-terminated multibyte-character destination string.

sizeInBytessizeInBytes
大小dest以字节为单位的缓冲区。Size of the dest buffer in bytes.

srcsrc
以 null 终止的多字节字符源字符串。Null-terminated multibyte-character source string.

countcount
从的字节数src要追加到destNumber of bytes from src to append to dest.

localelocale
要使用的区域设置。Locale to use.

返回值Return Value

如果成功,则为零;否则为错误代码。Zero if successful; otherwise, an error code.

错误条件Error Conditions

目标Dest sizeInBytessizeInBytes srcsrc 返回值Return value
NULLNULL 任何any 任何any EINVALEINVAL
任意Any <= 0<= 0 任何any EINVALEINVAL
任意Any 任何any NULLNULL EINVALEINVAL

如果出现任何一个错误状态,该函数生成无效参数错误,如参数验证中所述。If any of the error conditions occurs, the function generates an invalid parameter error, as described in Parameter Validation. 如果处理了错误,则该函数将返回EINVAL和设置errnoEINVALIf the error is handled, the function returns EINVAL and sets errno to EINVAL.

备注Remarks

_Mbsnbcat_s函数将追加到dest,最多,第一个计数字节的src。如果字节紧跟在 null 字符dest是前导字节,则将覆盖它的初始字节通过src。否则为的初始字节src覆盖的终止 null 字符destThe _mbsnbcat_s function appends to dest, at most, the first count bytes of src. If the byte that immediately precedes the null character in dest is a lead byte, it is overwritten by the initial byte of src. Otherwise, the initial byte of src overwrites the terminating null character of dest. 如果 null 字节出现在src之前计数字节追加, _mbsnbcat_s追加从所有字节src,最多 null字符。If a null byte appears in src before count bytes are appended, _mbsnbcat_s appends all bytes from src, up to the null character. 如果计数大于的长度src的长度src代替使用计数If count is greater than the length of src, the length of src is used in place of count. 生成的字符串由 null 字符终止。The resulting string is terminated by a null character. 如果复制出现在重叠的字符串之间,则该行为不确定。If copying takes place between strings that overlap, the behavior is undefined.

输出值受的设置LC_CTYPE的区域设置的类别设置影响; 请参阅setlocale、 _wsetlocale有关详细信息。The output value is affected by the setting of the LC_CTYPE category setting of the locale; see setlocale, _wsetlocale for more information. 这些函数的版本是相同的只不过不是具有 _l后缀使用当前区域设置的以及是否有 _l后缀改为使用的区域设置参数的在中传递。The versions of these functions are identical, except that the ones that don't have the _l suffix use the current locale and the ones that do have the _l suffix instead use the locale parameter that's passed in. 有关详细信息,请参阅 LocaleFor more information, see Locale.

在 C++ 中,使用这些函数由模板重载简化;重载可以自动推导出缓冲区长度,从而不再需要指定大小自变量,并且它们可以自动使用更新、更安全的函数替换较旧、不安全的函数。In C++, the use of these functions is simplified by template overloads; the overloads can infer buffer length automatically and thereby eliminate the need to specify a size argument, and they can automatically use their newer, more secure functions to replace older, less-secure functions. 有关详细信息,请参阅 Secure Template OverloadsFor more information, see Secure Template Overloads.

这些函数的调试版本首先用 0xFD 填充缓冲区。The debug versions of these functions first fill the buffer with 0xFD. 若要禁用此行为,请使用 _CrtSetDebugFillThresholdTo disable this behavior, use _CrtSetDebugFillThreshold.

一般文本例程映射Generic-Text Routine Mappings

Tchar.h 例程Tchar.h routine 未定义 _UNICODE 和 _MBCS_UNICODE and _MBCS not defined 已定义 _MBCS_MBCS defined 已定义 _UNICODE_UNICODE defined
_tcsncat_tcsncat strncatstrncat _mbsnbcat_s_mbsnbcat_s wcsncatwcsncat
_tcsncat_s_l_tcsncat_s_l _strncat_s_l_strncat_s_l _mbsnbcat_s_l_mbsnbcat_s_l _wcsncat_s_l_wcsncat_s_l

要求Requirements

例程Routine 必需的标头Required header
_mbsnbcat_s_mbsnbcat_s <mbstring.h><mbstring.h>
_mbsnbcat_s_l_mbsnbcat_s_l <mbstring.h><mbstring.h>

有关更多兼容性信息,请参阅 兼容性For more compatibility information, see Compatibility.

请参阅See also

字符串操作String Manipulation
_mbsnbcmp、_mbsnbcmp_l_mbsnbcmp, _mbsnbcmp_l
_strncnt、_wcsncnt、_mbsnbcnt、_mbsnbcnt_l、_mbsnccnt、_mbsnccnt_l_strncnt, _wcsncnt, _mbsnbcnt, _mbsnbcnt_l, _mbsnccnt, _mbsnccnt_l
_mbsnbcpy、_mbsnbcpy_l_mbsnbcpy, _mbsnbcpy_l
_mbsnbcpy_s、_mbsnbcpy_s_l_mbsnbcpy_s, _mbsnbcpy_s_l
_mbsnbset、_mbsnbset_l_mbsnbset, _mbsnbset_l
strncat、_strncat_l、wcsncat、_wcsncat_l、_mbsncat、_mbsncat_lstrncat, _strncat_l, wcsncat, _wcsncat_l, _mbsncat, _mbsncat_l
strncat_s、_strncat_s_l、wcsncat_s、_wcsncat_s_l、_mbsncat_s、_mbsncat_s_lstrncat_s, _strncat_s_l, wcsncat_s, _wcsncat_s_l, _mbsncat_s, _mbsncat_s_l