When opening a file with O_CREAT set, the file in question will be created if it does not already exist. I want special action to be taken only if the file is newly created. Is there a reliable way to check if this the case?
Currently I first attempt to open the file without O_CREAT and O_EXCL. If this fails, I then attempt to open with both of these set, and on success perform the special action. However, this is not atomic and fails if the file comes into existence between the two open attempts.