mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-31 19:40:33 +08:00
Cygwin: open: workaround reopen file w/ delete disposition set
On pre-W10 systems there's no way to reopen a file by handle if the delete disposition is set. We try to get around with duplicating the handle. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
0c545f3264
commit
ec36c59f1a
@ -693,6 +693,23 @@ fhandler_base::open (int flags, mode_t mode)
|
||||
|
||||
status = NtCreateFile (&fh, access, &attr, &io, NULL, file_attributes, shared,
|
||||
create_disposition, options, p, plen);
|
||||
/* Pre-W10, we can't open a file by handle with delete disposition
|
||||
set, so we have to lie our ass off. */
|
||||
if (get_handle () && status == STATUS_DELETE_PENDING)
|
||||
{
|
||||
BOOL ret = DuplicateHandle (GetCurrentProcess (), get_handle (),
|
||||
GetCurrentProcess (), &fh,
|
||||
access, !(flags & O_CLOEXEC), 0);
|
||||
if (!ret)
|
||||
ret = DuplicateHandle (GetCurrentProcess (), get_handle (),
|
||||
GetCurrentProcess (), &fh,
|
||||
0, !(flags & O_CLOEXEC),
|
||||
DUPLICATE_SAME_ACCESS);
|
||||
if (!ret)
|
||||
debug_printf ("DuplicateHandle after STATUS_DELETE_PENDING, %E");
|
||||
else
|
||||
status = STATUS_SUCCESS;
|
||||
}
|
||||
if (!NT_SUCCESS (status))
|
||||
{
|
||||
/* Trying to create a directory should return EISDIR, not ENOENT. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user