#include
#include
#include
#include
#include
void create_file(char *filename) {
if(creat(filename, 0777) < 0) {
printf("creat 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 the filename,please try again!\n");
exit(EXIT_FAILURE);
}
create_file(argv[1]);
exit(EXIT_SUCCESS);
}
==============================================
编译,查看:
[root@localhost guoqian_2]# gcc file_creat.c -o file_creat
[root@localhost guoqian_2]# ./file_creat 123
create file 123 success!
[root@localhost guoqian_2]# ll
总计 16
-rwxr-xr-x 1 root root 0 09-27 08:20 123
-rwxr-xr-x 1 root root 5235 09-27 08:20 file_creat
-rw-r--r-- 1 root root 494 09-27 08:16 file_creat.c
====================================================
原因在umask:
[root@localhost guoqian_2]# umask
0022
可见,umask屏蔽了写的权限
修改如下:umask -p 新的umask值
[root@localhost guoqian_2]# umask -p 0
[root@localhost guoqian_2]# umask
0000
阅读(1914) | 评论(0) | 转发(0) |