【问题标题】:How to give write permission to everybody?如何给每个人写权限?
【发布时间】:2019-04-05 00:25:59
【问题描述】:

以下代码运行后,文件tasty的权限位设置为0700,这是意料之外的。

#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

int main()
{
    int fild = creat("tasty", 0722);
    close(fild);
    return 0;
}

如何让每个人都写入文件?

【问题讨论】:

    标签: c unix permissions system-calls umask


    【解决方案1】:

    您的 shell 可能有一个 022 的 umask,这意味着创建的任何新文件都将清除指定的位(即组写入和其他写入)。

    创建文件前需要将umask设置为0:

    #include <fcntl.h>
    #include <unistd.h>
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    
    int main()
    {
        umask(0);
        int fild = creat("tasty", 0722);
        close(fild);
        return 0;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 2023-02-18
      • 1970-01-01
      • 1970-01-01
      • 2020-01-17
      • 1970-01-01
      相关资源
      最近更新 更多