Despite a thorough reading of the relevant standard documentation , I cannot understand what the expected behavior is in POSIX-compatible systems when an open system call is invoked with flags, including O_CREAT|O_DIRECTORY .
The standard states that
If O_CREAT and O_DIRECTORY are set and , the requested access mode is not O_WRONLY or O_RDWR, no result is specified.
However, it does not indicate system behavior with (O_CREAT|O_DIRECTORY|O_WRONLY) or with (O_CREAT|O_DIRECTORY|O_RDWR) . Indeed (as I understand it) the behavior of EISDIR applies only to existing directories.
In the O_CREATE section, the standard indicates that when a named file does not exist,
if O_DIRECTORY is not set , the file should be created as a regular file; [...]
but again, it is not indicated what will happen if O_DIRECTORY also set.
I have looked through the manual pages of NetBSD (which, as you know, cares a lot about POSIX compliance) and Linux (it is a widely used system, although it is actually not POSIX), but I cannot find any explanation.
Is it possible to say that the use of both flags is not specified? And if so, what is the most common behavior?
Is open(name, O_CREAT|O_DIRECTORY, mode) equivalent to mkdir for any POSIX compatible OS?
source share