From 2171fcea2c6bcf460d75d1020d68a16d5ea9cef0 Mon Sep 17 00:00:00 2001 From: sucongohu <1126045770@qq.com> Date: Mon, 5 Jun 2023 22:38:21 +0800 Subject: [PATCH] ioctl musl --- src/main.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index c682dd9..fdc2c42 100644 --- a/src/main.rs +++ b/src/main.rs @@ -485,7 +485,6 @@ extern "C" { fn ioctl(fd: i32, request: u64, ...) -> i32; } fn get_terminal_width() -> usize { - const TIOCGWINSZ: u64 = 0x40087468; #[repr(C)] struct Winsize { ws_row: u16, @@ -499,11 +498,13 @@ fn get_terminal_width() -> usize { ws_xpixel: 0, ws_ypixel: 0, }; - let fds = [0, 1, 2]; - for fd in &fds { - match unsafe { ioctl(*fd, TIOCGWINSZ, &mut size) } { - -1 => continue, - _ => break, + // 0x40087468 for glibc , 0x005413 for musl + for s in [0x40087468u64, 0x005413u64] { + for fd in [0, 1, 2] { + match unsafe { ioctl(fd, s, &mut size) } { + 0 => break, + _ => continue, + } } } size.ws_col as usize