From 52f95df61356bbd7a66af05d7490bc4b16513569 Mon Sep 17 00:00:00 2001 From: Hartmut Birr Date: Thu, 11 Aug 2005 19:37:29 +0000 Subject: [PATCH] Honour the inheritance of a handle if it would be duplicated or opened. svn path=/trunk/; revision=17295 --- reactos/lib/crt/io/dup.c | 6 ++++-- reactos/lib/crt/io/open.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/reactos/lib/crt/io/dup.c b/reactos/lib/crt/io/dup.c index 040497172cd..ed5a1c01389 100644 --- a/reactos/lib/crt/io/dup.c +++ b/reactos/lib/crt/io/dup.c @@ -13,25 +13,27 @@ int _dup(int handle) HANDLE hProcess = GetCurrentProcess(); BOOL result; int fd; + int mode; hFile = (HANDLE)_get_osfhandle(handle); if (hFile == INVALID_HANDLE_VALUE) { __set_errno(EBADF); return -1; } + mode = __fileno_getmode(handle); result = DuplicateHandle(hProcess, hFile, hProcess, &hFile, 0, - TRUE, + mode & FNOINHERIT ? FALSE : TRUE, DUPLICATE_SAME_ACCESS); if (result == FALSE) { _dosmaperr(GetLastError()); return -1; } - fd = alloc_fd(hFile, __fileno_getmode(handle)); + fd = alloc_fd(hFile, mode); if (fd < 0) { CloseHandle(hFile); diff --git a/reactos/lib/crt/io/open.c b/reactos/lib/crt/io/open.c index c32304c0002..b59623fe6a0 100644 --- a/reactos/lib/crt/io/open.c +++ b/reactos/lib/crt/io/open.c @@ -523,7 +523,7 @@ int __fileno_dup2(int handle1, int handle2) hProcess, &fdinfo(handle2)->hFile, 0, - TRUE, + fdinfo(handle1)->fdflags & FNOINHERIT ? FALSE : TRUE, DUPLICATE_SAME_ACCESS); if (result) { // _pioinfo[handle2]->fd = handle2;