This is the mail archive of the
cygwin-developers@sourceware.cygnus.com
mailing list for the Cygwin project.
RE: Problem with open() and O_CREAT
- To: 'Corinna Vinschen' <corinna at vinschen dot de>
- Subject: RE: Problem with open() and O_CREAT
- From: "Fifer, Eric" <EFifer at sanwaint dot com>
- Date: Fri, 17 Mar 2000 14:21:41 -0000
- Cc: "'cygwin-developers at sourceware dot cygnus dot com'" <cygwin-developers at sourceware dot cygnus dot com>
"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