# Function rustix::io::dup

source · [−]

    pub fn dup<Fd: AsFd>(fd: Fd) -> Result<OwnedFd>

Expand description

`dup(fd)`—Creates a new `OwnedFd` instance that shares the same underlying file description as `fd`.

This function does not set the `O_CLOEXEC` flag. To do a `dup` that does set `O_CLOEXEC`, use `fcntl_dupfd_cloexec`.

POSIX guarantees that `dup` will use the lowest unused file descriptor, however it is not safe in general to rely on this, as file descriptors may be unexpectedly allocated on other threads or in libraries.

## References

- POSIX
- Linux
- Apple