pub fn dup2<Fd: AsFd>(fd: Fd, new: &mut OwnedFd) -> Result<()>
Expand description
dup2(fd, new)
—Changes the file description of a file descriptor.
dup2
conceptually closes new
and then sets the file description for
new
to be the same as the one for fd
. This is a very unusual operation,
and should only be used on file descriptors where you know how new
will
be subsequently used.
This function does not set the O_CLOEXEC
flag. To do a dup2
that does
set O_CLOEXEC
, use dup3
with [DupFlags::CLOEXEC
] on platforms which
support it, or fcntl_dupfd_cloexec