open() O_EXCL 参数讲解
fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
O_EXCL一般和O_CREAT同时出现, 意思是如果filename不存在, 则新建之.
如果已经存在, 则打开文件失败: fd < 0.
O_EXCL
If O_CREAT and O_EXCL are set, open() shall fail if the file exists. The check for the existence of the file and the creation of the file if it does not exist shall be atomic with respect to other threads executing open() naming the same filename in the same directory with O_EXCL and O_CREAT set. If O_EXCL and O_CREAT are set, and path names a symbolic link, open() shall fail and set errno to [EEXIST], regardless of the contents of the symbolic link. If O_EXCL is set and O_CREAT is not set, the result is undefined.
O_EXCL参数详解
本文详细解析了Linux系统调用open()中的O_EXCL参数作用。当与O_CREAT结合使用时,若目标文件已存在,则打开操作将失败,确保文件创建的原子性和唯一性。文章深入探讨了该参数在多线程环境下的应用及与符号链接交互时的行为。
1397

被折叠的 条评论
为什么被折叠?



