|
|
|
@ -24,6 +24,8 @@ impl Clone for ManagedFD {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO: io::Read/io::Write impls for ManagedFD
|
|
|
|
|
|
|
|
|
|
impl ManagedFD
|
|
|
|
|
{
|
|
|
|
|
#[inline]
|
|
|
|
@ -32,6 +34,18 @@ impl ManagedFD
|
|
|
|
|
Self(UnmanagedFD::new_unchecked(fd))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Duplicate a file-descriptor, aliasing the open resource for the lifetime of the returned `ManagedFD`..
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn alias(file: &(impl AsRawFd + ?Sized)) -> io::Result<Self>
|
|
|
|
|
{
|
|
|
|
|
let r = unsafe { libc::dup(file.as_raw_fd()) };
|
|
|
|
|
if let Some(r) = UnmanagedFD::new_raw(r) {
|
|
|
|
|
Ok(Self(r))
|
|
|
|
|
} else {
|
|
|
|
|
Err(io::Error::last_os_error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub const fn take_raw(fd: RawFd) -> Self
|
|
|
|
|
{
|
|
|
|
@ -101,6 +115,3 @@ impl From<ManagedFD> for std::fs::File
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: implement the rest of ManagedFD from `memfd` module in `utf8encode`
|
|
|
|
|