_strset、_strset_l、_wcsset、_wcsset_l、_mbsset、_mbsset_l
将字符串的字符设置为一个字符。 有关这些函数的更多安全版本,请参见 _strset_s、_strset_s_l、_wcsset_s、_wcsset_s_l、_mbsset_s、_mbsset_s_l。
重要
_mbsset 和 _mbsset_l 不能用于在 Windows 运行时 中执行应用程序。有关详细信息,请参见 CRT functions not supported with /ZW(CRT 函数不支持使用/ZW)。
char *_strset(
char *str,
int c
);
char *_strset_l(
char *str,
int c,
locale_t locale
);
wchar_t *_wcsset(
wchar_t *str,
wchar_t c
);
wchar_t *_wcsset_l(
wchar_t *str,
wchar_t c,
locale_t locale
);
unsigned char *_mbsset(
unsigned char *str,
unsigned int c
);
unsigned char *_mbsset_l(
unsigned char *str,
unsigned int c,
_locale_t locale
);
参数
str
设置 null 终止的字符串。c
字符设置。locale
要使用的区域设置。
返回值
返回指向修改后的字符串的指针。
备注
_strset 函数将 c 设置为str 的所有字符 (不包括终止 null 字符) ,转换为 char。 _wcsset 和 _mbsset_l 是 _strset的宽字符和多字节字符版本,并且参数的数据类型和返回值相应地改变。 否则这些函数具有相同行为。
_mbsset验证其参数。 如果 str 是空指针,则会调用无效参数处理程序,如 参数验证 所述。 如果允许执行继续, _mbsset 返回 NULL并设置errno 为 EINVAL。 _strset 和 _wcsset 不验证其参数。
输出值受区域设置的 LC_CTYPE 类设置影响;有关更多信息,请参见 setlocale、_wsetlocale。 除了不具有使用当前区域的 _l 后缀以及具有 _l 后缀而不是使用传入的区域参数,这些函数的版本相同。 有关详细信息,请参阅区域设置。
安全说明 |
---|
这些函数可能容易受到的缓冲区溢出的威胁。缓冲区溢出可以用于系统攻击,因为它们可能使权限的提升不能确保。有关更多信息,请参见避免缓冲区溢出。 |
一般文本例程映射
TCHAR.H 例程 |
未定义 _UNICODE & _MBCS |
已定义 _MBCS |
已定义 _UNICODE |
---|---|---|---|
_tcsset |
_strset |
_mbsset |
_wcsset |
_tcsset_l |
_strset_l |
_mbsset_l |
_wcsset_l |
要求
例程 |
必需的标头 |
---|---|
_strset |
<string.h> |
_strset_l |
<tchar.h> |
_wcsset |
<string.h> 或 <wchar.h> |
_wcsset_l |
<tchar.h> |
_mbsset, _mbsset_l |
<mbstring.h> |
有关其他兼容性信息,请参见兼容性。
示例
// crt_strset.c
// compile with: /W3
#include <string.h>
#include <stdio.h>
int main( void )
{
char string[] = "Fill the string with something.";
printf( "Before: %s\n", string );
_strset( string, '*' ); // C4996
// Note: _strset is deprecated; consider using _strset_s instead
printf( "After: %s\n", string );
}
.NET Framework 等效项
不适用。若要调用标准 C 函数,请使用 PInvoke。有关详细信息,请参阅平台调用示例。