fixup! Implement isatty

This commit is contained in:
jD91mZM2
2018-07-26 14:32:10 +02:00
parent 2bf426b0fb
commit 8b48b6959c
5 changed files with 27 additions and 5 deletions
+8
View File
@@ -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
}
+9
View File
@@ -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
}
+9
View File
@@ -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
}
-1
View File
@@ -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,
+1 -4
View File
@@ -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]