Skip to content

Commit 6b1bcb3

Browse files
committed
Impl new fn Stdio::from_raw_fd_owned
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
1 parent 155852f commit 6b1bcb3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/stdio.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ impl Stdio {
4747
pub const fn inherit() -> Self {
4848
Self(StdioImpl::Inherit)
4949
}
50+
51+
/// `Stdio::from_raw_fd_owned` takes ownership of the fd passed in
52+
/// and closes the fd on drop.
53+
///
54+
/// NOTE that the fd will be put into blocking mode, then it will be
55+
/// closed when `Stdio` is dropped.
56+
///
57+
/// # Safety
58+
///
59+
/// * `fd` - must be a valid fd and must give its ownership to `Stdio`.
60+
pub unsafe fn from_raw_fd_owned(fd: RawFd) -> Self {
61+
Self(StdioImpl::Fd(OwnedFd::from_raw_fd(fd), true))
62+
}
5063
}
5164
/// FromRawFd takes ownership of the fd passed in
5265
/// and closes the fd on drop.

0 commit comments

Comments
 (0)