Skip to content

Commit

Permalink
feat: impl AsFd for PtyMaster (nix-rust#2355)
Browse files Browse the repository at this point in the history
  • Loading branch information
yshui authored Apr 9, 2024
1 parent 0517893 commit 391a364
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/2355.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `impl AsFd for pty::PtyMaster`
6 changes: 6 additions & 0 deletions src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ impl AsRawFd for PtyMaster {
}
}

impl AsFd for PtyMaster {
fn as_fd(&self) -> BorrowedFd<'_> {
self.0.as_fd()
}
}

impl IntoRawFd for PtyMaster {
fn into_raw_fd(self) -> RawFd {
let fd = self.0;
Expand Down
3 changes: 2 additions & 1 deletion test/test_pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ use nix::unistd::{pause, write};
fn test_ptsname_equivalence() {
let _m = crate::PTSNAME_MTX.lock();

// Open a new PTTY master
// Open a new PTY master
let master_fd = posix_openpt(OFlag::O_RDWR).unwrap();
assert!(master_fd.as_raw_fd() > 0);
assert!(master_fd.as_fd().as_raw_fd() == master_fd.as_raw_fd());

// Get the name of the slave
let slave_name = unsafe { ptsname(&master_fd) }.unwrap();
Expand Down

0 comments on commit 391a364

Please sign in to comment.