FD_RENUMBER
Atomically replace a file descriptor by renumbering another file descriptor.
Due to the strong focus on thread safety, this environment does not provide a mechanism to duplicate or renumber 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 function provides a way to atomically renumber file descriptors, which would disappear if dup2()
were to be removed entirely.
(@interface func (export "fd_renumber")
(param $fd $fd)
;;; The file descriptor to overwrite.
(param $to $fd)
(result $error (expected (error $errno)))
)
Content copied to clipboard