diff --git a/src/platform/src/linux/mod.rs b/src/platform/src/linux/mod.rs index 4b61ba7541f81d2f0ff5f35714313a2799ec09bd..3b1683bc8c283c0c4449d78b68cd5f656755131e 100644 --- a/src/platform/src/linux/mod.rs +++ b/src/platform/src/linux/mod.rs @@ -3,6 +3,8 @@ use core::{mem, ptr}; use errno; use types::*; +const TIOCGWINSZ: u32 = 0x5413; + const AT_FDCWD: c_int = -100; const AT_EMPTY_PATH: c_int = 0x1000; const AT_REMOVEDIR: c_int = 0x200; @@ -215,9 +217,15 @@ pub fn getuid() -> uid_t { } pub fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) -> c_int { + // TODO: Somehow support varargs to syscall?? e(unsafe { syscall!(IOCTL, fd, request, out) }) as c_int } +pub fn isatty(fd: c_int) -> c_int { + let mut winsize = winsize::default(); + (ioctl(fd, TIOCGWINSZ as c_ulong, &mut winsize as *mut _ as *mut c_void) == 0) as c_int +} + pub fn kill(pid: pid_t, sig: c_int) -> c_int { e(unsafe { syscall!(KILL, pid, sig) }) as c_int } diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs index f778d7665ea763b889b058a1b9712638d5bf23e3..0ee98d55a94295ed06e8dc2864b2fc9609967d95 100644 --- a/src/platform/src/redox/mod.rs +++ b/src/platform/src/redox/mod.rs @@ -470,6 +470,15 @@ pub fn getuid() -> uid_t { e(syscall::getuid()) as pid_t } +pub fn isatty(fd: c_int) -> c_int { + syscall::dup(fd as usize, b"termios") + .map(|fd| { + let _ = syscall::close(fd); + 1 + }) + .unwrap_or(0) +} + pub fn kill(pid: pid_t, sig: c_int) -> c_int { e(syscall::kill(pid, sig as usize)) as c_int } diff --git a/src/platform/src/types.rs b/src/platform/src/types.rs index 6d4902ed2a5a2c68a73aad45f63ba18751324d28..5124a52abeb3bd682bbd5bf9196b8f7ad4b83785 100644 --- a/src/platform/src/types.rs +++ b/src/platform/src/types.rs @@ -188,3 +188,12 @@ pub struct dirent { pub d_type: c_uchar, pub d_name: [c_char; 256] } + +#[repr(C)] +#[derive(Default)] +pub struct winsize { + ws_row: c_ushort, + ws_col: c_ushort, + ws_xpixel: c_ushort, + ws_ypixel: c_ushort +} diff --git a/src/sys_ioctl/src/lib.rs b/src/sys_ioctl/src/lib.rs index de1f7e0d114ae586ed18aec510a0be48be605f6a..ac99a318fdb95e95ef0c1ff64b13dd89242b0719 100644 --- a/src/sys_ioctl/src/lib.rs +++ b/src/sys_ioctl/src/lib.rs @@ -9,7 +9,6 @@ pub mod inner { use self::platform::types::*; #[repr(C)] - #[derive(Default)] pub struct winsize { ws_row: c_ushort, ws_col: c_ushort, diff --git a/src/unistd/src/lib.rs b/src/unistd/src/lib.rs index a6a1ab2939f803a42553cf4ff89ddcaf58d0f6ee..49c5a6b580c0dce5bbd1fcf8ec8658c70deb16f6 100644 --- a/src/unistd/src/lib.rs +++ b/src/unistd/src/lib.rs @@ -6,12 +6,10 @@ extern crate errno; extern crate platform; extern crate stdio; extern crate string; -extern crate sys_ioctl; use core::{ptr, slice}; use platform::types::*; -use sys_ioctl::{ioctl, winsize}; pub use brk::*; pub use getopt::*; @@ -264,8 +262,7 @@ pub extern "C" fn getwd(path_name: *mut c_char) -> *mut c_char { #[no_mangle] pub extern "C" fn isatty(fd: c_int) -> c_int { - let mut winsize = winsize::default(); - (ioctl(fd, sys_ioctl::TIOCGWINSZ as c_ulong, &mut winsize as *mut _ as *mut c_void) == 0) as c_int + platform::isatty(fd) } // #[no_mangle]