使用 O_CREAT 或 O_TMPFILE 调用“open”,但缺少模式

问题描述 投票:0回答:1

在 Linux 上,我使用以下代码打开一个文件:

auto file = ::open("file.dat", O_RDWR | O_CREAT);

但是当我尝试为 Android (android-ndk-r26-beta2) 编译此代码时,出现以下编译器错误:

error: 'open' called with O_CREAT or O_TMPFILE, but missing mode

我应该传递什么值才能编译?文档在哪里?

据我所知,它是仿生。它的状态如何?

android android-ndk posix
1个回答
0
投票

应该是这样的:

auto file = ::open("file.dat", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);

参见https://codeql.github.com/codeql-query-help/cpp/cpp-open-call-with-mode-argument/

© www.soinside.com 2019 - 2024. All rights reserved.