fixup! Implement isatty
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user