tmpfile_s
创建一个临时文件: tmpfile 的安全增强版本,如CRT 中的安全功能所述。
errno_t tmpfile_s(
FILE** pFilePtr
);
参数
- [out] pFilePtr
存储流的生成的指针地址的指针地址。
返回值
如果成功,则返回零;如果失败,则返回错误代码。
错误情况
pFilePtr |
返回值 |
Contents of pFilePtr |
---|---|---|
NULL |
EINVAL |
不更改 |
如果以上参数验证错误发生,则调用无效参数句柄,如 参数验证所述。 如果允许执行继续,则将 errno 设置为 EINVAL,并且返回值为EINVAL。
备注
tmpfile_s 函数创建临时文件并在 pFilePtr 参数中放入指向该流的指针。 临时文件在根目录中创建。 若要创建目录中(非根目录)的一个临时文件,可与 fopen一起使用tmpnam_s或tempnam。
如果文件无法打开,tmpfile_s 写 NULL 到 pFilePtr 参数。 该临时文件自动删除,当关闭文件,那么,当程序时通常停止,或者当调用 _rmtmp 后,假定,当前工作目录不更改。 临时文件在 w+b (二进制) 读/可写模式打开。
如果尝试带有tmpfile_s.的TMP_MAX_S调用(请参见STDIO.H),则可能失败。
要求
例程 |
必需的标头 |
---|---|
tmpfile_s |
<stdio.h> |
有关其他兼容性信息,请参见“简介”中的兼容性。
示例
备注
此示例需要管理权限才能在 Windows Vista 上运行。
// crt_tmpfile_s.c
// This program uses tmpfile_s to create a
// temporary file, then deletes this file with _rmtmp.
//
#include <stdio.h>
int main( void )
{
FILE *stream;
char tempstring[] = "String to be written";
int i;
errno_t err;
// Create temporary files.
for( i = 1; i <= 3; i++ )
{
err = tmpfile_s(&stream);
if( err )
perror( "Could not open new temporary file\n" );
else
printf( "Temporary file %d was created\n", i );
}
// Remove temporary files.
printf( "%d temporary files deleted\n", _rmtmp() );
}
.NET Framework 等效项
不适用。若要调用标准 C 函数,请使用 PInvoke。有关更多信息,请参见平台调用示例。