int mkstemp(char *template);
mkstemp函数在系统中以唯一的文件名创建一个文件并打开,而且只有当前用户才能访问这个临时文件,并进行读、写操作。
建立唯一临时文件名, template须以数组形式声明而非指针形式.
在glibc 2.0.6 以及更早的glibc库中这个文件的访问权限是0666,glibc 2.0.7以后的库这个文件的访问权限是0600。
由于mkstemp函数创建的临时文件不能自动删除,所以执行完mkstemp函数后要调用unlink函数,unlink函数删除文件的目录入口,
下面是一个使用mkstemp的例子:
- int main(void)
- {
- int fd;
- char temp_file[]="tmp_XXXXXX";
- /*Creat a temp file.*/
- if((fd=mkstemp(temp_file))==-1)
- {
- printf("Creat temp file faile./n");
- exit(1);
- }
- /*Unlink the temp file.*/
- unlink(temp_file);
- close(fd);
- }
2万+




被折叠的 条评论
为什么被折叠?



