Function cloudabi::fd_replace [] [src]

pub unsafe fn fd_replace(from_: fd, to_: fd) -> errno

Atomically replaces a file descriptor by a copy of another file descriptor.

Due to the strong focus on thread safety, this environment does not provide a mechanism to duplicate a file descriptor to an arbitrary number, like dup2(). This would be prone to race conditions, as an actual file descriptor with the same number could be allocated by a different thread at the same time.

This system call provides a way to atomically replace file descriptors, which would disappear if dup2() were to be removed entirely.

Parameters

from: The file descriptor that needs to be copied.

to: The file descriptor that needs to be overwritten.