Skip to content

Commit

Permalink
use unsafe close
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 committed Jun 6, 2024
1 parent 42f3552 commit 23b6009
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,25 @@ impl Pty {
#[allow(dead_code)]
pub fn close(&mut self) -> Result<(), napi::Error> {
if let Some(fd) = self.controller_fd.take() {
drop(fd);
unsafe {
if libc::close(fd.as_raw_fd()) == -1 {
return Err(napi::Error::new(
napi::Status::GenericFailure,
format!("close failed: {}", Error::last_os_error()),
));
}
};
}

if let Some(fd) = self.user_fd.take() {
drop(fd);
unsafe {
if libc::close(fd.as_raw_fd()) == -1 {
return Err(napi::Error::new(
napi::Status::GenericFailure,
format!("close failed: {}", Error::last_os_error()),
));
}
};
}

Ok(())
Expand Down

0 comments on commit 23b6009

Please sign in to comment.