gpt4 book ai didi

c - fopen() 创建权限模式

转载 作者:太空狗 更新时间:2023-10-29 15:26:58 31 4
gpt4 key购买 nike

根据OpenGroup ,如果用 O_CREAT 调用 open() 并且文件尚不存在,它将使用指定为函数中第三个参数的文件权限创建:

the file shall be created; the user ID of the file shall be set to the effective user ID of the process; the group ID of the file shall be set to the group ID of the file's parent directory or to the effective group ID of the process; and the access permission bits (see ) of the file mode shall be set to the value of the third argument taken as type mode_t

是否可以用 fopen() 做一些类似的事情,这样我就可以在创建新文件时设置权限,而不必事后对其进行 chmod?

最佳答案

来自 fopen(3) 手册页:

Any created files will have mode S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH (0666), as modified by the process's umask value (see umask(2)).

所以 umask(2) 是你的 friend 。

关于c - fopen() 创建权限模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15511456/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com