UNIX创建临时文件
生活随笔
收集整理的這篇文章主要介紹了
UNIX创建临时文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*
?* =====================================================================================
?*
?* ? ? ? 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;
?* =====================================================================================
?*
?* ? ? ? 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,且沒有進程打開它,這文件就會被刪除,目錄立刻被刪除,而文件占用的空間等到最后一個進程關閉它之后被系統回收。?
*/
總結
以上是生活随笔為你收集整理的UNIX创建临时文件的全部內容,希望文章能夠幫你解決所遇到的問題。