- 积分
- 101
贡献111
飞刀0 FD
注册时间2011-11-29
在线时间20 小时

扫一扫,手机访问本帖 
|
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#define RWRWRW S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
void create_file(char *filename)
{
umask(S_IRGRP|S_IROTH);
if(creat(filename, RWRWRW ) < 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[])
{
mode_t mask = umask(0);
if(argc<2)
{
perror("you han't input the filename,please try again!\n");
exit(EXIT_FAILURE);
}
create_file(argv[1]);
exit(EXIT_SUCCESS);
}
执行:gcc file_creat.c -o file_creat
root@boyang-virtual-machine:/opt/set1# ./file_creat file1
-rw-r--r-- 1 root root 0 12月 15 13:27 file1
在从新编译下:
gcc file_creat.c -o file_creat
root@boyang-virtual-machine:/opt/set1# ./file_creat file1
-rw-r--r-- 1 root root 0 12月 15 13:34 file1
只有在更改文件名后文件的属性才能更改,问什么?
root@boyang-virtual-machine:/opt/set1# ./file_creat file5
-rw--w--w- 1 root root 0 12月 15 13:36 file5
|
|