嵌入式爱好者

查看: 13123|回复: 1

[Linux] crente()文件属性问题

[复制链接]

32

主题

76

帖子

101

积分

扫一扫,手机访问本帖
发表于 2014-12-15 13:37:52 | 显示全部楼层 |阅读模式
#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
回复

使用道具 举报

32

主题

76

帖子

101

积分

 楼主| 发表于 2014-12-17 14:16:26 | 显示全部楼层
没有人回答这个问题?
点评回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )

GMT+8, 2025-3-14 18:33

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表