gpt4 book ai didi

linux - 如果文件由 'open' 创建但没有指定 'mode',模式将是什么?

转载 作者:太空宇宙 更新时间:2023-11-04 09:37:11 24 4
gpt4 key购买 nike

我尝试像这样在当前目录中创建一个文件“foo”:

打开("foo", O_CREAT | O_EXCL | O_RDWR);

第三个参数我没有给它一个“模式”,那么它会是什么呢?在我的 ubuntu 14.04 上,这个新文件的模式似乎是一个随机值。“模式”没有任何默认值吗?

最佳答案

在POSIX的man 3p open中没有说的很清楚,但是在linux的man 2 open中:

int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);

mode specifies the permissions to use in case a new file is created. This argument must be supplied when O_CREAT or O_TMPFILE is specified in flags.

也就是说,如果 mode 在应该提供的时候没有提供,则结果是未定义

关于linux - 如果文件由 'open' 创建但没有指定 'mode',模式将是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25348014/

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