Skip to content

Commit

Permalink
[#50296] Apply linter and formater
Browse files Browse the repository at this point in the history
  • Loading branch information
k-juszczyk committed Nov 24, 2023
1 parent e316dd3 commit 5a74589
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
6 changes: 2 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ fn main() {
let mut bgen;

// termios lib
bgen = bindgen::Builder::default()
.header(format!("{CLIB_THIRD_PARTY_DIR}/termios/termios.h"));
bgen = bindgen::Builder::default().header(format!("{CLIB_THIRD_PARTY_DIR}/termios/termios.h"));
bgen.clang_arg(format!(
"--sysroot={}/share/wasi-sysroot",
env!("WASI_SDK_PATH")
Expand All @@ -59,8 +58,7 @@ fn main() {
.expect("could not write termios bindings");

// general lib
bgen = bindgen::Builder::default()
.header(format!("{CLIB_DIR}/wasi_ext_lib.h"));
bgen = bindgen::Builder::default().header(format!("{CLIB_DIR}/wasi_ext_lib.h"));
if cfg!(feature = "hterm") {
bgen = bgen.clang_arg("-DHTERM");
}
Expand Down
34 changes: 14 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ pub enum Redirect {
Close(Fd),
}

pub enum TcsetattrAction { TCSANOW, TCSADRAIN, TCSAFLUSH, }
pub enum TcsetattrAction {
TCSANOW,
TCSADRAIN,
TCSAFLUSH,
}

impl From<&Redirect> for wasi_ext_lib_generated::Redirect {
fn from(redirect: &Redirect) -> Self {
Expand Down Expand Up @@ -413,10 +417,7 @@ pub fn umount(path: &str) -> Result<(), ExitCode> {
pub fn tcgetattr(fd: Fd) -> Result<termios::termios, ExitCode> {
let mut termios_p: termios::termios = unsafe { mem::zeroed() };
let result = unsafe {
termios::wasi_ext_tcgetattr(
fd as c_int,
&mut termios_p as *mut termios::termios
)
termios::wasi_ext_tcgetattr(fd as c_int, &mut termios_p as *mut termios::termios)
};

if result == 0 {
Expand All @@ -426,19 +427,19 @@ pub fn tcgetattr(fd: Fd) -> Result<termios::termios, ExitCode> {
}
}

pub fn tcsetattr(fd: Fd, act: TcsetattrAction, termios_p: &termios::termios) -> Result<(), ExitCode> {
pub fn tcsetattr(
fd: Fd,
act: TcsetattrAction,
termios_p: &termios::termios,
) -> Result<(), ExitCode> {
let act_num = match act {
TcsetattrAction::TCSANOW => termios::TCSANOW,
TcsetattrAction::TCSADRAIN => termios::TCSADRAIN,
TcsetattrAction::TCSAFLUSH => termios::TCSAFLUSH,
} as c_int;

let result = unsafe {
termios::wasi_ext_tcsetattr(
fd as c_int,
act_num,
termios_p as *const termios::termios
)
termios::wasi_ext_tcsetattr(fd as c_int, act_num, termios_p as *const termios::termios)
};

if result == 0 {
Expand All @@ -452,10 +453,7 @@ pub fn tcgetwinsize(fd: Fd) -> Result<termios::winsize, ExitCode> {
let mut winsize: termios::winsize = unsafe { mem::zeroed() };

let result = unsafe {
termios::wasi_ext_tcgetwinsize(
fd as c_int,
&mut winsize as *mut termios::winsize
)
termios::wasi_ext_tcgetwinsize(fd as c_int, &mut winsize as *mut termios::winsize)
};

if result == 0 {
Expand All @@ -466,9 +464,5 @@ pub fn tcgetwinsize(fd: Fd) -> Result<termios::winsize, ExitCode> {
}

pub fn cfmakeraw(termios_p: &mut termios::termios) {
unsafe {
termios::wasi_ext_cfmakeraw(
termios_p as *mut termios::termios
)
};
unsafe { termios::wasi_ext_cfmakeraw(termios_p as *mut termios::termios) };
}

0 comments on commit 5a74589

Please sign in to comment.