c - 使用奇怪的权限打开创建文件

标签 c

一开始我用的是

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;
}

enter image description here

最佳答案

正如 @JohnBollinger 在评论中指出的,我没有正确保存文件,我使用的是 666 而不是 0666

关于c - 使用奇怪的权限打开创建文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55835314/

相关文章:

c - 头文件无法工作 - 对 `method' 的 undefined reference

c - 如何限制用户在C中输入一位小数点的 float

c - 如何从标准输入读取矩阵并放入C中的二维数组

c++ - C++ 和 C 中的 header 保护

c - 使用 getw() 读取问题

c - 解析 CSV 文本行时出错

objective-c - 如何排除 arc4random 中的数字?

c - 骨架代码 : character pointers struggles

c - 如何从字面上打印 f %d

c - 是C语言的内存泄漏吗?