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;