对于文件所有者 00700,系统调用 open ()
只允许将模式设置为 S_IRWXU
(根据我的手册页),所有者是 rwx
。我想删除所有者通过我的 C 程序执行这个新制作的文件的权利。
不幸的是,chmod
没有提供更改所有者权限的方法(据我正确理解手册页)所以我认为有一种方法可以通过一些参数直接指定所需的行为-魔法。
int out;
out = open(cmd->outFile, O_WRONLY | O_TRUNC | O_CREAT, /*set the rights correctly to (rw-r--r--)*/
最佳答案
For the file-owner 00700 the system call
open ()
only allows to set mode toS_IRWXU
(according to my man page) for the owner which isrwx
.
那将是一个奇怪的手册页;见man open
- O_CREAT 的描述指向 <sys/stat.h> ,其中 S_IRWXU 只是访问权限位宏列表的第一个。
I want to delete the owners right to execute this newly made file via my C program.
如果您在创建文件时就指定了所需的权限,则以后无需删除其中任何一个。
要使用 rw-r--r--
创建文件,open
调用可以是:
out = open(cmd->outFile, O_WRONLY|O_TRUNC|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
关于c - 使用 (rw-r--r--) 打开 ( ) 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40971267/