From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 70452 invoked by alias); 5 Jun 2019 11:56:24 -0000 Mailing-List: contact cygwin-cvs-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-cvs-owner@cygwin.com Received: (qmail 70423 invoked by uid 9078); 5 Jun 2019 11:56:24 -0000 Date: Wed, 05 Jun 2019 11:56:00 -0000 Message-ID: <20190605115624.70421.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] mkdir: always check-for-existence X-Act-Checkin: newlib-cygwin X-Git-Author: Ben Wijen X-Git-Refname: refs/heads/master X-Git-Oldrev: 5c2a3661c1aeefb0591ce46e8ab3274f0c6d9112 X-Git-Newrev: b0c033bf3fae810b9e5a5c69f17bd4de63725691 X-SW-Source: 2019-q2/txt/msg00071.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=b0c033bf3fae810b9e5a5c69f17bd4de63725691 commit b0c033bf3fae810b9e5a5c69f17bd4de63725691 Author: Ben Wijen Date: Mon Jun 3 20:15:50 2019 +0200 mkdir: always check-for-existence When using NtCreateFile when creating a directory that already exists, it will correctly return 'STATUS_OBJECT_NAME_COLLISION'. However using this function to create a directory (and all its parents) a normal use would be to start with mkdir(‘/cygdrive/c’) which translates to ‘C:\’ for which it'll instead return ‘STATUS_ACCESS_DENIED’. Diff: --- winsup/cygwin/dir.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc index f43eae4..b757851 100644 --- a/winsup/cygwin/dir.cc +++ b/winsup/cygwin/dir.cc @@ -331,8 +331,10 @@ mkdir (const char *dir, mode_t mode) debug_printf ("got %d error from build_fh_name", fh->error ()); set_errno (fh->error ()); } + else if (fh->exists ()) + set_errno (EEXIST); else if (has_dot_last_component (dir, true)) - set_errno (fh->exists () ? EEXIST : ENOENT); + set_errno (ENOENT); else if (!fh->mkdir (mode)) res = 0; delete fh;