sys: impl AsFd for PTY

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2022-10-19 14:36:45 +02:00
parent 34688a6d74
commit cfa77e0e88

View File

@ -2,7 +2,7 @@
//!
//! see [PTY](struct.PTY.html) for an example on how to use it
use std::os::unix::io::{AsRawFd, RawFd};
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd};
use nix::fcntl::OFlag;
use nix::pty::{grantpt, posix_openpt, ptsname_r, unlockpt, PtyMaster};
@ -125,3 +125,9 @@ impl AsRawFd for PTY {
self.primary.as_raw_fd()
}
}
impl AsFd for PTY {
fn as_fd(&self) -> BorrowedFd<'_> {
unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
}
}