title: What's the expected behavior of open(name, O_CREAT|O_DIRECTORY, mode)?
body: <p>Despite a careful read of <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html" rel="noreferrer">the related standard documentation</a>, I can't understand what's the expected behavior in POSIX compliant systems when a <code>open</code> system call is invoked with flags including <code>O_CREAT|O_DIRECTORY</code>.</p>
  
  <p>The standard specifies that</p>
  
  <blockquote>
    <p>If O_CREAT and O_DIRECTORY are set <strong>and</strong> the requested access mode is neither O_WRONLY nor O_RDWR, the result is unspecified.</p>
  </blockquote>
  
  <p>However it does not specify the behavior of the system with neither <code>(O_CREAT|O_DIRECTORY|O_WRONLY)</code> nor <code>(O_CREAT|O_DIRECTORY|O_RDWR)</code>. Indeed (as far as I can understand) the behavior on <code>EISDIR</code> only apply to <strong>existing</strong> directories.</p>
  
  <p>In the section related to O_CREATE, the standard specifies that, when the named file does not exist,</p>
  
  <blockquote>
    <p>if O_DIRECTORY <strong>is not set</strong> the file shall be created as a regular file; [...]</p>
  </blockquote>
  
  <p>but again it does not specify what will happen if <code>O_DIRECTORY</code> is set too.</p>
  
  <p>I've looked the manual pages of both <a href="http://netbsd.gw.com/cgi-bin/man-cgi?open%202%20NetBSD-current" rel="noreferrer">NetBSD</a> (which notoriously cares a lot about POSIX compliance) and <a href="https://linux.die.net/man/2/open" rel="noreferrer">Linux</a> (which is a widely used system, despite not actually a POSIX one) but I can't find any clarification.</p>
  
  <p>Is it correct to say that the use of both flags is unspecified?
  And if so, what's the most common behavior?  </p>
  
  <p>Is <code>open(name, O_CREAT|O_DIRECTORY, mode)</code>  equivalent to <code>mkdir</code> on any POSIX compliant OS?</p>