Skip to content

Commit

Permalink
check for error when getting fcntl flags
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonkaliski committed Jan 31, 2024
1 parent 645d292 commit 852d90e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ fn set_controlling_terminal(fd: c_int) -> Result<(), Error> {
fn set_nonblocking(fd: c_int) -> Result<(), NAPI_ERROR> {
use libc::{fcntl, F_GETFL, F_SETFL, O_NONBLOCK};

let res = unsafe { fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK) };
let status_flags = unsafe { fcntl(fd, F_GETFL, 0) };

if status_flags < 0 {
return Err(NAPI_ERROR::new(
napi::Status::GenericFailure,
format!("fcntl F_GETFL failed: {}", Error::last_os_error()),
));
}

let res = unsafe { fcntl(fd, F_SETFL, status_flags | O_NONBLOCK) };

if res != 0 {
return Err(NAPI_ERROR::new(
Expand Down

0 comments on commit 852d90e

Please sign in to comment.