/** * Creates a new duplicate of a standard file handle. * * Constructs a new \a file_handle object that owns a duplicate of a * standard file handle. The \a d parameter specifies which standard * file handle to duplicate and can be one of \a STD_INPUT_HANDLE, * \a STD_OUTPUT_HANDLE or \a STD_ERROR_HANDLE. The duplicate's * inheritable flag is set to the value of \a inheritable. * * This operation is only available in Windows systems. * * \pre \a d refers to one of the standard handles as described above. * \return A file handle owning a duplicate of the standard handle * referred to by \a d. * \throw boost::system::system_error If GetStdHandle() or * DuplicateHandle() fails. */ static file_handle win32_std(DWORD d, bool inheritable) { BOOST_ASSERT(d == STD_INPUT_HANDLE || d == STD_OUTPUT_HANDLE || d == STD_ERROR_HANDLE); HANDLE h = ::GetStdHandle(d); if (h == INVALID_HANDLE_VALUE) boost::throw_exception(boost::system::system_error(boost::system::error_code(::GetLastError(), boost::system::get_system_category()), "boost::process::detail::file_handle::win32_std: GetStdHandle failed")); return win32_dup(h, inheritable); }
int __wrap_dup(int oldfd) { int rc; rc = win32_dup(oldfd); /* -1 means we should've win32_dup'd it but it failed */ if(rc == -1) return -1; if(rc > 0) return rc; return __real_dup(oldfd); }
inline file_handle file_handle::win32_std(DWORD d, bool inheritable) { BOOST_ASSERT(d == STD_INPUT_HANDLE || d == STD_OUTPUT_HANDLE || d == STD_ERROR_HANDLE); HANDLE h = ::GetStdHandle(d); if (h == INVALID_HANDLE_VALUE) boost::throw_exception (system_error("boost::process::detail::file_handle::win32_std", "GetStdHandle failed", ::GetLastError())); return win32_dup(h, inheritable); }