ITeye博客

UNIX创建临时文件

vergilwang · 2011-11-04 13:26 · Linux · C++ · 编程语言 · Markdown

/*
* =====================================================================================
*
* Filename: tmp_file.c
*
* Description:
*
* Version: 1.0
* Created: 2011年11月04日 11时54分36秒
* Revision: none
* Compiler: gcc
*
* Author: Wang Ran (), wangran51@126.com
* Company:
*
* =====================================================================================
*/

#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
int tmp = open("tmp.txt", O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IXUSR);//O_CREAT按照mode中给出的模式创建文件,O_EXCL如果文件已经存在则open失败
unlink("tmp.txt");
return EXIT_SUCCESS;

}

/*

当一个文件的链接数减少到0,且没有进程打开它,这文件就会被删除,目录立刻被删除,而文件占用的空间等到最后一个进程关闭它之后被系统回收。

 

*/

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。