_mbsnbset_s, _mbsnbset_s_l
Set the first n bytes of a multibyte-character string to a specified character. Versions of _mbsnbset, _mbsnbset_l with security enhancements as described in Security Enhancements in the CRT.
errno_t _mbsnbset_s(
unsigned char *str,
size_t size,
unsigned int c,
size_t count
);
errno_t _mbsnbset_s_l(
unsigned char *str,
size_t size,
unsigned int c,
size_t count,
_locale_t locale
);
template <size_t size>
errno_t _mbsnbset_s(
unsigned char (&str)[size],
unsigned int c,
size_t count
); // C++ only
template <size_t size>
errno_t _mbsnbset_s_l(
unsigned char (&str)[size],
unsigned int c,
size_t count,
_locale_t locale
); // C++ only
Параметры
str
String to be altered.size
The size of the string buffer.c
Single-byte or multibyte-character setting.count
Number of bytes to be set.locale
Locale to use.
Возвращаемое значение
Zero if successful; an error code otherwise.
Заметки
The _mbsnbset_s and _mbsnbset_s_l functions set, at most, the first count bytes of str to c. If count is greater than the length of str, the length of str is used instead of count. If c is a multibyte character and cannot be set entirely into the last byte specified by count, the last byte is padded with a blank character. _mbsnbset_s and _mbsnbset_s_l do not place a terminating null at the end of str.
_mbsnbset_s and _mbsnbset_s_l are similar to _mbsnset, except that they set count bytes rather than count characters of c.
If str is NULL or count is zero, this function generates an invalid parameter exception as described in Parameter Validation. If execution is allowed to continue, errno is set to EINVAL and the function returns NULL. Also, if c is not a valid multibyte character, errno is set to EINVAL and a space is used instead.
The output value is affected by the setting of the LC_CTYPE category setting of the locale; see setlocale for more information. The _mbsnbset_s version of this function uses the current locale for this locale-dependent behavior; the _mbsnbset_s_l version is identical except that it use the locale parameter passed in instead. For more information, see Locale.
In C++, using these functions is simplified by template overloads; the overloads can infer buffer length automatically, eliminating the need to specify a size argument. For more information, see Secure Template Overloads.
The debug versions of these functions first fill the buffer with 0xFD. To disable this behavior, use _CrtSetDebugFillThreshold.
Generic-Text Routine Mappings
Tchar.h routine |
_UNICODE and _MBCS not defined |
_MBCS defined |
_UNICODE defined |
---|---|---|---|
_tcsnset_s |
_strnset_s |
_mbsnbset_s |
_wcsnset_s |
_tcsnset_s_l |
_strnset_s _l |
_mbsnbset_s_l |
_wcsnset_s_l |
Требования
Routine |
Required header |
---|---|
_mbsnbset_s |
<mbstring.h> |
_mbsnbset_s_l |
<mbstring.h> |
For more compatibility information, see Compatibility in the Introduction.
Пример
// crt_mbsnbset_s.c
#include <mbstring.h>
#include <stdio.h>
int main( void )
{
char string[15] = "This is a test";
/* Set not more than 4 bytes of string to be *'s */
printf( "Before: %s\n", string );
_mbsnbset_s( string, sizeof(string), '*', 4 );
printf( "After: %s\n", string );
}
Output
Before: This is a test After: **** is a test
Эквивалент в .NET Framework
Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
См. также
Основные понятия
_strnset, _strnset_l, _wcsnset, _wcsnset_l, _mbsnset, _mbsnset_l