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.