Kind of get bash to compile
Doesn't link yet due to "multiple definitions of malloc", because some are supplied by some library of bash itself. Really odd.
This commit is contained in:
@@ -3,6 +3,10 @@ use core::{mem, ptr};
|
||||
use errno;
|
||||
use types::*;
|
||||
|
||||
const EINVAL: c_int = 22;
|
||||
|
||||
const TCGETS: c_ulong = 0x5401;
|
||||
const TCSETS: c_ulong = 0x5402;
|
||||
const TIOCGWINSZ: c_ulong = 0x5413;
|
||||
|
||||
const AT_FDCWD: c_int = -100;
|
||||
@@ -420,6 +424,21 @@ pub fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *m
|
||||
e(unsafe { syscall!(SOCKETPAIR, domain, kind, protocol, socket_vector) }) as c_int
|
||||
}
|
||||
|
||||
pub fn tcgetattr(fd: c_int, out: *mut termios) -> c_int {
|
||||
ioctl(fd, TCGETS, out as *mut c_void)
|
||||
}
|
||||
|
||||
pub fn tcsetattr(fd: c_int, act: c_int, value: *const termios) -> c_int {
|
||||
if act < 0 || act > 2 {
|
||||
unsafe {
|
||||
errno = EINVAL;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
// This is safe because ioctl shouldn't modify the value
|
||||
ioctl(fd, TCSETS + act as c_ulong, value as *mut c_void)
|
||||
}
|
||||
|
||||
pub fn times(out: *mut tms) -> clock_t {
|
||||
unsafe { syscall!(TIMES, out) as clock_t }
|
||||
}
|
||||
|
||||
@@ -992,6 +992,42 @@ pub fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *m
|
||||
-1
|
||||
}
|
||||
|
||||
pub fn tcgetattr(fd: c_int, out: *mut termios) -> c_int {
|
||||
let dup = e(syscall::dup(fd as usize, b"termios"));
|
||||
if dup == !0 {
|
||||
return -1;
|
||||
}
|
||||
|
||||
let read = e(syscall::read(dup, unsafe { slice::from_raw_parts_mut(
|
||||
out as *mut u8,
|
||||
mem::size_of::<termios>()
|
||||
) }));
|
||||
let _ = syscall::close(dup);
|
||||
|
||||
if read == !0 {
|
||||
return -1;
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
pub fn tcsetattr(fd: c_int, _act: c_int, value: *const termios) -> c_int {
|
||||
let dup = e(syscall::dup(fd as usize, b"termios"));
|
||||
if dup == !0 {
|
||||
return -1;
|
||||
}
|
||||
|
||||
let write = e(syscall::write(dup, unsafe { slice::from_raw_parts(
|
||||
value as *const u8,
|
||||
mem::size_of::<termios>()
|
||||
) }));
|
||||
let _ = syscall::close(dup);
|
||||
|
||||
if write == !0 {
|
||||
return -1;
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
pub fn times(out: *mut tms) -> clock_t {
|
||||
let _ = write!(FileWriter(2), "unimplemented: times({:p})", out);
|
||||
!0
|
||||
|
||||
@@ -241,3 +241,21 @@ pub const F_OK: c_int = 0;
|
||||
pub const R_OK: c_int = 4;
|
||||
pub const W_OK: c_int = 2;
|
||||
pub const X_OK: c_int = 1;
|
||||
|
||||
pub type cc_t = u8;
|
||||
pub type speed_t = u32;
|
||||
pub type tcflag_t = u32;
|
||||
|
||||
pub const NCCS: usize = 32;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct termios {
|
||||
c_iflag: tcflag_t,
|
||||
c_oflag: tcflag_t,
|
||||
c_cflag: tcflag_t,
|
||||
c_lflag: tcflag_t,
|
||||
c_line: cc_t,
|
||||
c_cc: [cc_t; NCCS],
|
||||
__c_ispeed: speed_t,
|
||||
__c_ospeed: speed_t
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user