Skip to content

Commit

Permalink
move around usafe {}
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonkaliski committed Jan 31, 2024
1 parent cc0b74e commit 645d292
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
15 changes: 4 additions & 11 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@
/* auto-generated by NAPI-RS */

export class Pty {
fd: number;
pid: number;
constructor(
command: string,
args: Array<string>,
envs: Record<string, string>,
dir: string,
size: [cols: number, rows: number],
onExit: (err: null | Error, exitCode: number) => void,
);
resize(size: [cols: number, rows: number]): void;
fd: number
pid: number
constructor(command: string, args: Array<string>, envs: Record<string, string>, dir: string, size: [cols: number, rows: number], onExit: (err: null | Error, exitCode: number) => void)
resize(size: [cols: number, rows: number]): void
}
8 changes: 3 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ fn set_controlling_terminal(fd: c_int) -> Result<(), Error> {
}

#[allow(dead_code)]
unsafe fn set_nonblocking(fd: c_int) -> Result<(), NAPI_ERROR> {
fn set_nonblocking(fd: c_int) -> Result<(), NAPI_ERROR> {
use libc::{fcntl, F_GETFL, F_SETFL, O_NONBLOCK};

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

if res != 0 {
return Err(NAPI_ERROR::new(
Expand Down Expand Up @@ -131,9 +131,7 @@ impl Pty {

let pid = child.id();

unsafe {
set_nonblocking(fd_controller)?;
}
set_nonblocking(fd_controller)?;

let file = File::from(pty_pair.controller);
let fd = file.as_raw_fd();
Expand Down

0 comments on commit 645d292

Please sign in to comment.