www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/2000/03/17/09:28:10

Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-developers-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin-developers/>
List-Post: <mailto:cygwin-developers AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-developers-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-developers-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin-developers AT sourceware DOT cygnus DOT com
Message-ID: <779F20BCCE5AD31186A50008C75D9979171704@SILLDN_MAIL1>
From: "Fifer, Eric" <EFifer AT sanwaint DOT com>
To: "'Corinna Vinschen'" <corinna AT vinschen DOT de>
Cc: "'cygwin-developers AT sourceware DOT cygnus DOT com'"
<cygwin-developers AT sourceware DOT cygnus DOT com>
Subject: RE: Problem with open() and O_CREAT
Date: Fri, 17 Mar 2000 14:21:41 -0000
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2448.0)

"Corinna Vinschen" wrote:
>[...]
>your patch looks ok to me. Thank you!
>[...]
>But I wonder if we couldn't do without the request for the state
>of `creation_distribution'. Shouldn't this be enough when asking
>for GetLastError() == ERROR_ALREADY_EXISTS? I think so, because
>O_CREAT implies CREATE_ALWAYS or OPEN_ALWAYS if O_EXCL isn't
>used whereas O_EXCL results in a different behaviour, either.

I agree.  Although, I had to carefully reread MSDN and stare
at the code.  As you point out O_CREAT and O_EXCL result
in CREATE_NEW and in this case if the file already exists, the
CreateFile() will fail (instead of succeeding and setting
ERROR_ALREADY_EXISTS as it does with CREATE_ALWAYS or OPEN_ALWAYS).

Anyway, the simplified patch now becomes:

diff -rup winsup.orig/cygwin/fhandler.cc winsup/cygwin/fhandler.cc
--- winsup.orig/cygwin/fhandler.cc      Fri Mar 17 04:55:11 2000
+++ winsup/cygwin/fhandler.cc   Fri Mar 17 13:41:07 2000
@@ -340,7 +340,8 @@ fhandler_base::open (int flags, mode_t m
       goto done;
     }
 
-  if (flags & O_CREAT && get_device () == FH_DISK)
+  if (flags & O_CREAT && get_device () == FH_DISK &&
+      GetLastError () != ERROR_ALREADY_EXISTS)
     set_file_attribute (has_acls (), get_win32_name (), mode);
 
   namehash_ = hash_path_name (0, get_win32_name ());


Thanks.

Eric

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019