The real meaning of O_EXCL is "error if create and file exists" but the name is derived from "EXCLusive", which is a bit misleading though and causes many people to misinterpret that flag.
Opening a file with O_EXCL will not give you exclusive access to it as some people incorrectly assume. A file opened with O_EXCL by one process can be be opened by other processes for reading and even writing at the very same time, no problem, so access is clearly not exclusive.
The main reason why this flag exists are "lock files". Long before there was file advisory locking (with fcntl) and semaphores/mutexes that can be shared among processes, a simple way was required to ensure atomic access to certain system resources across multiple processes. The way to realize that were lock files. The first process that wanted to have access to a resource would create a lock file in /var/lock to claim ownership of that resource and delete it again once done with it. Other processes would monitor that directory and thus know if a resource is available or not.
The problem: If two processes look into the directory and both see that a certain file is not present, so the resource is available, and now both try to create this file, how to ensure that only one of both will ever succeed? And that's where O_EXCL comes into play. If they both try to create that files with O_EXCL set, this operation will only succeed for one of them and that's the process which now owns the resource lock.
So O_EXCL is not for getting exclusive access to a file, it is for making exclusive access files whose purpose is to regulate exclusive access to some kind of resource.
The second most important usage of O_EXCL today is file access security. Consider this case: A root process wants to create a file and fill it with content that only the root user shall be able to ever see, not ordinary users, but it is creating it in a directory ordinary users do have write access to (e.g. /tmp). If the process would create the file as follows
open("/tmp/root-only", O_CREAT | O_WRONLY, 0600);
and the file does not exist, it is created, owned by root and only root has read and write access to it, so ordinary users cannot see its content. Mission accomplished.
But what if an ordinary user has already created /tmp/root-only before? Then this file is owned by that user, this user can have read access to it and the open call above will just open the existing file. Even if the root process changes ownership and file permission directly after opening the file, this has no effect on a process that already has opened the file before (e.g. tail -f).
So the correct way to implement that case is in fact:
unlink("/tmp/root-only"); // best effort, may not even exist
open("/tmp/root-only", O_CREAT | O_EXCL | O_WRONLY, 0600);
In case open does succeed, the process can rely that the file is owned by the process owner and nobody else has access permissions to read/write it.
OPEN_EXCLUSIVE.readOnly = O_RDONLY,). You don't want to allow for an accidental reordering or deletion to change meaning of any of your enum values.