public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* mkdir(2) prefers EACCES over EEXIST
@ 2017-07-12  1:12 Christopher Wellons
  2017-07-12  8:46 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Christopher Wellons @ 2017-07-12  1:12 UTC (permalink / raw)
  To: cygwin

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:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: mkdir(2) prefers EACCES over EEXIST
  2017-07-12  1:12 mkdir(2) prefers EACCES over EEXIST Christopher Wellons
@ 2017-07-12  8:46 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2017-07-12  8:46 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1377 bytes --]

On Jul 11 21:12, Christopher Wellons wrote:
> 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.

That's a result of calling the Windows function without prior check for
existence.  The Windows function apparently prefers it's variation of
EACCES over EEXIST, *iff* the target of the function is a drive.

I don't think it's worth to add a check to mkdir for such a border
case, just to prefer one error code over another.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-12  8:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-12  1:12 mkdir(2) prefers EACCES over EEXIST Christopher Wellons
2017-07-12  8:46 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).