| 498 | #[cfg(not(any(windows, target_os = "wasi")))] |
| 499 | #[inline] |
| 500 | pub fn dup2_stdout<Fd: AsFd>(fd: Fd) -> io::Result<()> { |
| 501 | let fd = fd.as_fd(); |
| 502 | if fd.as_raw_fd() != c::STDOUT_FILENO { |
| 503 | // SAFETY: We wrap the returned `OwnedFd` to `ManuallyDrop` so that it |
| 504 | // isn't dropped. |
| 505 | let mut target = ManuallyDrop::new(unsafe { take_stdout() }); |
| 506 | backend::io::syscalls::dup2(fd, &mut target)?; |
| 507 | } |
| 508 | Ok(()) |
| 509 | } |
| 510 | |
| 511 | /// Utility function to safely `dup2` over stderr (fd 2). |
| 512 | #[cfg(not(any(windows, target_os = "wasi")))] |