gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 16:18:43 25 4
gpt4 key购买 nike

一开始我用的是

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/

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