gpt4 book ai didi

c - 与 O_CREAT|O_EXCL 相反

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:23:16 24 4
gpt4 key购买 nike

在 Linux 上的 C 中有没有办法只写入一个已经存在的文件?换句话说,与 open(..., O_CREAT|O_EXCL) 相反。

请注意,我不希望存在性检查与文件的实际打开分离(例如预先调用 stat()),因为那将是竞争条件。

最佳答案

尝试在没有 O_CREAT 标志的情况下打开文件时检查 ENOENT

ENOENT O_CREAT is not set and the named file does not exist; or O_CREAT is set and either the path prefix does not exist or the path argument points to an empty string.

关于c - 与 O_CREAT|O_EXCL 相反,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17789696/

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