一开始我用的是
fd = open(outputfile,O_WRONLY | O_TRUNC | O_CREAT);
它给了我随机文件权限,但现在我正在使用
fd = open(outputfile,O_WRONLY | O_TRUNC | O_CREAT, 0666);
这段代码生成文件完全相同的文件权限,但它们很奇怪。 我实际上想要 -rw-rw-rw- 但我得到:
--w---x--T 1 root root 21 Apr 24 13:02 fasdfas
在另一个系统上:
--w--wx--T 1 s8771-26 s8771-26 21 Apr 24 22:09 test1
--w--wx--T 1 s8771-26 s8771-26 21 Apr 24 22:09 test2
--w--wx--T 1 s8771-26 s8771-26 21 Apr 24 22:09 test3
--w--wx--T 1 s8771-26 s8771-26 21 Apr 24 22:09 test4
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char ** argv)
{
int fd = open(argv[1],O_WRONLY | O_TRUNC | O_CREAT, 0666);
dup2(fd,1);
printf("TEST");
return 0;
}
最佳答案
正如 @JohnBollinger 在评论中指出的,我没有正确保存文件,我使用的是 666 而不是 0666
关于c - 使用奇怪的权限打开创建文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55835314/