Despite a careful read of the related standard documentation, I can't understand what's the expected behavior in POSIX compliant systems when a open
system call is invoked with flags including O_CREAT|O_DIRECTORY
.
The standard specifies that
If O_CREAT and O_DIRECTORY are set and the requested access mode is neither O_WRONLY nor O_RDWR, the result is unspecified.
However it does not specify the behavior of the system with neither (O_CREAT|O_DIRECTORY|O_WRONLY)
nor (O_CREAT|O_DIRECTORY|O_RDWR)
. Indeed (as far as I can understand) the behavior on EISDIR
only apply to existing directories.
In the section related to O_CREATE, the standard specifies that, when the named file does not exist,
if O_DIRECTORY is not set the file shall be created as a regular file; [...]
but again it does not specify what will happen if O_DIRECTORY
is set too.
I've looked the manual pages of both NetBSD (which notoriously cares a lot about POSIX compliance) and Linux (which is a widely used system, despite not actually a POSIX one) but I can't find any clarification.
Is it correct to say that the use of both flags is unspecified? And if so, what's the most common behavior?
Is open(name, O_CREAT|O_DIRECTORY, mode)
equivalent to mkdir
on any POSIX compliant OS?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With