Skip to content

Commit

Permalink
try without cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 committed Jun 6, 2024
1 parent 26e702e commit 6720477
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,19 @@ impl Pty {
#[allow(dead_code)]
pub fn fd(&mut self) -> Result<c_int, napi::Error> {
if let Some(fd) = &self.controller_fd {
let res = unsafe { libc::fcntl(fd.as_raw_fd(), libc::F_DUPFD_CLOEXEC, 3) };
if res < 0 {
return Err(napi::Error::new(
napi::Status::GenericFailure,
format!("fcntl F_DUPFD_CLOEXEC failed: {}", Error::last_os_error()),
));
}

Ok(res)
Ok(fd.as_raw_fd())
// let fd_handle = fd.try_clone()?.as_raw_fd();
// Ok(fd_handle)

// let res = unsafe { libc::fcntl(fd.as_raw_fd(), libc::F_DUPFD_CLOEXEC, 3) };
// if res < 0 {
// return Err(napi::Error::new(
// napi::Status::GenericFailure,
// format!("fcntl F_DUPFD_CLOEXEC failed: {}", Error::last_os_error()),
// ));
// }
//
// Ok(res)
} else {
Err(napi::Error::new(
napi::Status::GenericFailure,
Expand Down

0 comments on commit 6720477

Please sign in to comment.