mkdir(2) prefers EACCES over EEXIST

Christopher Wellons
Wed Jul 12 01:12:00 GMT 2017

This isn't _really_ a bug, more of an oddity. Calling mkdir(2) on an 
existing directory will fail with EACCES instead of EEXIST if the 
directory couldn't have been created in the first place. For example, 
this is the typical situation for /cygdrive/c:

    mkdir("/cygdrive/c", 0700);
    // errno == EACCES

Or from the shell:

    $ mkdir /cygdrive/c
    mkdir: cannot create directory ‘/cygdrive/c’: Permission denied

Compare that to Linux or *BSD (giving EEXIST):

    $ mkdir /etc
    mkdir: cannot create directory ‘/etc’: File exists

    $ mkdir /etc
    mkdir: /etc: File exists

This behavior seems to be permitted by POSIX — both are valid reasons 
for this system call to fail — but it's a surprising result. I'd expect 
existence to take priority.

Problem reports:
Unsubscribe info:

More information about the Cygwin mailing list