文件编程-create

来源:互联网 发布:华3c多镜像端口配置 编辑:程序博客网 时间:2024/05/17 06:53
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
void create_file(char * filename)
{
/*创建的文件具有可读可写的属性*/
if( creat(filename,0666)<0 )
{
printf("create file %s failure !\n",filename);
exit(EXIT_FAILURE);
}
else
{
printf("create file %s success!\n",filename);
}
}
int main(int argc,char *argv[])
{
/*判断入参有没有传入文件名*/
if(argc < 2)
{
perror("you haven't input th filename,please try again1\n");
exit(EXIT_FAILURE);
}
create_file(argv[1]);
return 0;
}
/*
*新创建的文件也要符合umask要求
*/