Implement setitimer/getitimer/alarm/ualarm

This commit is contained in:
jD91mZM2
2018-07-27 08:22:17 +02:00
parent 8b48b6959c
commit 1b40f2d463
8 changed files with 277 additions and 184 deletions
Generated
+1 -1
View File
@@ -656,7 +656,7 @@ dependencies = [
"platform 0.1.0",
"stdio 0.1.0",
"string 0.1.0",
"sys_ioctl 0.1.0",
"sys_time 0.1.0",
]
[[package]]
+10 -2
View File
@@ -3,7 +3,7 @@ use core::{mem, ptr};
use errno;
use types::*;
const TIOCGWINSZ: u32 = 0x5413;
const TIOCGWINSZ: c_ulong = 0x5413;
const AT_FDCWD: c_int = -100;
const AT_EMPTY_PATH: c_int = 0x1000;
@@ -161,6 +161,10 @@ pub unsafe fn gethostname(mut name: *mut c_char, len: size_t) -> c_int {
0
}
pub fn getitimer(which: c_int, out: *mut itimerval) -> c_int {
e(unsafe { syscall!(GETITIMER, which, out) }) as c_int
}
pub unsafe fn getpeername(
socket: c_int,
address: *mut sockaddr,
@@ -223,7 +227,7 @@ pub fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) -> 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
(ioctl(fd, TIOCGWINSZ, &mut winsize as *mut _ as *mut c_void) == 0) as c_int
}
pub fn kill(pid: pid_t, sig: c_int) -> c_int {
@@ -325,6 +329,10 @@ pub unsafe fn sendto(
)) as ssize_t
}
pub fn setitimer(which: c_int, new: *const itimerval, old: *mut itimerval) -> c_int {
e(unsafe { syscall!(SETITIMER, which, new, old) }) as c_int
}
pub fn setpgid(pid: pid_t, pgid: pid_t) -> c_int {
e(unsafe { syscall!(SETPGID, pid, pgid) }) as c_int
}
+29
View File
@@ -401,6 +401,20 @@ unsafe fn inner_get_name(
Ok(0)
}
pub fn getitimer(which: c_int, out: *mut itimerval) -> c_int {
let _ = write!(
::FileWriter(2),
"unimplemented: getitimer({}, {:p})",
which,
out
);
unsafe {
*out = itimerval::default();
}
0
}
pub unsafe fn getpeername(
socket: c_int,
address: *mut sockaddr,
@@ -642,6 +656,21 @@ pub unsafe fn sendto(
write(socket, slice::from_raw_parts(buf as *const u8, len))
}
pub fn setitimer(which: c_int, new: *const itimerval, old: *mut itimerval) -> c_int {
let _ = write!(
::FileWriter(2),
"unimplemented: setitimer({}, {:p}, {:p})",
which,
new,
old
);
unsafe {
*old = itimerval::default();
}
0
}
pub fn setpgid(pid: pid_t, pgid: pid_t) -> c_int {
e(syscall::setpgid(pid as usize, pgid as usize)) as c_int
}
+8
View File
@@ -78,6 +78,7 @@ pub struct timespec {
}
#[repr(C)]
#[derive(Default)]
pub struct timeval {
pub tv_sec: time_t,
pub tv_usec: suseconds_t,
@@ -89,6 +90,13 @@ pub struct timezone {
pub tz_dsttime: c_int,
}
#[repr(C)]
#[derive(Default)]
pub struct itimerval {
pub it_interval: timeval,
pub it_value: timeval,
}
#[cfg(target_os = "redox")]
impl<'a> From<&'a timespec> for redox_timespec {
fn from(tp: &timespec) -> redox_timespec {
+171 -171
View File
@@ -22,193 +22,193 @@ pub mod inner {
platform::ioctl(fd, request, out)
}
pub const TCGETS: u32 = 0x5401;
pub const TCSETS: u32 = 0x5402;
pub const TCSETSW: u32 = 0x5403;
pub const TCSETSF: u32 = 0x5404;
pub const TCGETA: u32 = 0x5405;
pub const TCSETA: u32 = 0x5406;
pub const TCSETAW: u32 = 0x5407;
pub const TCSETAF: u32 = 0x5408;
pub const TCSBRK: u32 = 0x5409;
pub const TCXONC: u32 = 0x540A;
pub const TCFLSH: u32 = 0x540B;
pub const TIOCEXCL: u32 = 0x540C;
pub const TIOCNXCL: u32 = 0x540D;
pub const TIOCSCTTY: u32 = 0x540E;
pub const TIOCGPGRP: u32 = 0x540F;
pub const TIOCSPGRP: u32 = 0x5410;
pub const TIOCOUTQ: u32 = 0x5411;
pub const TIOCSTI: u32 = 0x5412;
pub const TIOCGWINSZ: u32 = 0x5413;
pub const TIOCSWINSZ: u32 = 0x5414;
pub const TIOCMGET: u32 = 0x5415;
pub const TIOCMBIS: u32 = 0x5416;
pub const TIOCMBIC: u32 = 0x5417;
pub const TIOCMSET: u32 = 0x5418;
pub const TIOCGSOFTCAR: u32 = 0x5419;
pub const TIOCSSOFTCAR: u32 = 0x541A;
pub const FIONREAD: u32 = 0x541B;
pub const TIOCINQ: u32 = FIONREAD;
pub const TIOCLINUX: u32 = 0x541C;
pub const TIOCCONS: u32 = 0x541D;
pub const TIOCGSERIAL: u32 = 0x541E;
pub const TIOCSSERIAL: u32 = 0x541F;
pub const TIOCPKT: u32 = 0x5420;
pub const FIONBIO: u32 = 0x5421;
pub const TIOCNOTTY: u32 = 0x5422;
pub const TIOCSETD: u32 = 0x5423;
pub const TIOCGETD: u32 = 0x5424;
pub const TCSBRKP: u32 = 0x5425;
pub const TIOCSBRK: u32 = 0x5427;
pub const TIOCCBRK: u32 = 0x5428;
pub const TIOCGSID: u32 = 0x5429;
pub const TIOCGRS485: u32 = 0x542E;
pub const TIOCSRS485: u32 = 0x542F;
pub const TIOCGPTN: u32 = 0x80045430;
pub const TIOCSPTLCK: u32 = 0x40045431;
pub const TIOCGDEV: u32 = 0x80045432;
pub const TCGETX: u32 = 0x5432;
pub const TCSETX: u32 = 0x5433;
pub const TCSETXF: u32 = 0x5434;
pub const TCSETXW: u32 = 0x5435;
pub const TIOCSIG: u32 = 0x40045436;
pub const TIOCVHANGUP: u32 = 0x5437;
pub const TIOCGPKT: u32 = 0x80045438;
pub const TIOCGPTLCK: u32 = 0x80045439;
pub const TIOCGEXCL: u32 = 0x80045440;
pub const TIOCGPTPEER: u32 = 0x5441;
pub const TCGETS: c_ulong = 0x5401;
pub const TCSETS: c_ulong = 0x5402;
pub const TCSETSW: c_ulong = 0x5403;
pub const TCSETSF: c_ulong = 0x5404;
pub const TCGETA: c_ulong = 0x5405;
pub const TCSETA: c_ulong = 0x5406;
pub const TCSETAW: c_ulong = 0x5407;
pub const TCSETAF: c_ulong = 0x5408;
pub const TCSBRK: c_ulong = 0x5409;
pub const TCXONC: c_ulong = 0x540A;
pub const TCFLSH: c_ulong = 0x540B;
pub const TIOCEXCL: c_ulong = 0x540C;
pub const TIOCNXCL: c_ulong = 0x540D;
pub const TIOCSCTTY: c_ulong = 0x540E;
pub const TIOCGPGRP: c_ulong = 0x540F;
pub const TIOCSPGRP: c_ulong = 0x5410;
pub const TIOCOUTQ: c_ulong = 0x5411;
pub const TIOCSTI: c_ulong = 0x5412;
pub const TIOCGWINSZ: c_ulong = 0x5413;
pub const TIOCSWINSZ: c_ulong = 0x5414;
pub const TIOCMGET: c_ulong = 0x5415;
pub const TIOCMBIS: c_ulong = 0x5416;
pub const TIOCMBIC: c_ulong = 0x5417;
pub const TIOCMSET: c_ulong = 0x5418;
pub const TIOCGSOFTCAR: c_ulong = 0x5419;
pub const TIOCSSOFTCAR: c_ulong = 0x541A;
pub const FIONREAD: c_ulong = 0x541B;
pub const TIOCINQ: c_ulong = FIONREAD;
pub const TIOCLINUX: c_ulong = 0x541C;
pub const TIOCCONS: c_ulong = 0x541D;
pub const TIOCGSERIAL: c_ulong = 0x541E;
pub const TIOCSSERIAL: c_ulong = 0x541F;
pub const TIOCPKT: c_ulong = 0x5420;
pub const FIONBIO: c_ulong = 0x5421;
pub const TIOCNOTTY: c_ulong = 0x5422;
pub const TIOCSETD: c_ulong = 0x5423;
pub const TIOCGETD: c_ulong = 0x5424;
pub const TCSBRKP: c_ulong = 0x5425;
pub const TIOCSBRK: c_ulong = 0x5427;
pub const TIOCCBRK: c_ulong = 0x5428;
pub const TIOCGSID: c_ulong = 0x5429;
pub const TIOCGRS485: c_ulong = 0x542E;
pub const TIOCSRS485: c_ulong = 0x542F;
pub const TIOCGPTN: c_ulong = 0x80045430;
pub const TIOCSPTLCK: c_ulong = 0x40045431;
pub const TIOCGDEV: c_ulong = 0x80045432;
pub const TCGETX: c_ulong = 0x5432;
pub const TCSETX: c_ulong = 0x5433;
pub const TCSETXF: c_ulong = 0x5434;
pub const TCSETXW: c_ulong = 0x5435;
pub const TIOCSIG: c_ulong = 0x40045436;
pub const TIOCVHANGUP: c_ulong = 0x5437;
pub const TIOCGPKT: c_ulong = 0x80045438;
pub const TIOCGPTLCK: c_ulong = 0x80045439;
pub const TIOCGEXCL: c_ulong = 0x80045440;
pub const TIOCGPTPEER: c_ulong = 0x5441;
pub const FIONCLEX: u32 = 0x5450;
pub const FIOCLEX: u32 = 0x5451;
pub const FIOASYNC: u32 = 0x5452;
pub const TIOCSERCONFIG: u32 = 0x5453;
pub const TIOCSERGWILD: u32 = 0x5454;
pub const TIOCSERSWILD: u32 = 0x5455;
pub const TIOCGLCKTRMIOS: u32 = 0x5456;
pub const TIOCSLCKTRMIOS: u32 = 0x5457;
pub const TIOCSERGSTRUCT: u32 = 0x5458;
pub const TIOCSERGETLSR: u32 = 0x5459;
pub const TIOCSERGETMULTI: u32 = 0x545A;
pub const TIOCSERSETMULTI: u32 = 0x545B;
pub const FIONCLEX: c_ulong = 0x5450;
pub const FIOCLEX: c_ulong = 0x5451;
pub const FIOASYNC: c_ulong = 0x5452;
pub const TIOCSERCONFIG: c_ulong = 0x5453;
pub const TIOCSERGWILD: c_ulong = 0x5454;
pub const TIOCSERSWILD: c_ulong = 0x5455;
pub const TIOCGLCKTRMIOS: c_ulong = 0x5456;
pub const TIOCSLCKTRMIOS: c_ulong = 0x5457;
pub const TIOCSERGSTRUCT: c_ulong = 0x5458;
pub const TIOCSERGETLSR: c_ulong = 0x5459;
pub const TIOCSERGETMULTI: c_ulong = 0x545A;
pub const TIOCSERSETMULTI: c_ulong = 0x545B;
pub const TIOCMIWAIT: u32 = 0x545C;
pub const TIOCGICOUNT: u32 = 0x545D;
pub const FIOQSIZE: u32 = 0x5460;
pub const TIOCMIWAIT: c_ulong = 0x545C;
pub const TIOCGICOUNT: c_ulong = 0x545D;
pub const FIOQSIZE: c_ulong = 0x5460;
pub const TIOCPKT_DATA: u32 = 0;
pub const TIOCPKT_FLUSHREAD: u32 = 1;
pub const TIOCPKT_FLUSHWRITE: u32 = 2;
pub const TIOCPKT_STOP: u32 = 4;
pub const TIOCPKT_START: u32 = 8;
pub const TIOCPKT_NOSTOP: u32 = 16;
pub const TIOCPKT_DOSTOP: u32 = 32;
pub const TIOCPKT_IOCTL: u32 = 64;
pub const TIOCPKT_DATA: c_ulong = 0;
pub const TIOCPKT_FLUSHREAD: c_ulong = 1;
pub const TIOCPKT_FLUSHWRITE: c_ulong = 2;
pub const TIOCPKT_STOP: c_ulong = 4;
pub const TIOCPKT_START: c_ulong = 8;
pub const TIOCPKT_NOSTOP: c_ulong = 16;
pub const TIOCPKT_DOSTOP: c_ulong = 32;
pub const TIOCPKT_IOCTL: c_ulong = 64;
pub const TIOCSER_TEMT: u32 = 0x01;
pub const TIOCSER_TEMT: c_ulong = 0x01;
pub const TIOCM_LE: u32 = 0x001;
pub const TIOCM_DTR: u32 = 0x002;
pub const TIOCM_RTS: u32 = 0x004;
pub const TIOCM_ST: u32 = 0x008;
pub const TIOCM_SR: u32 = 0x010;
pub const TIOCM_CTS: u32 = 0x020;
pub const TIOCM_CAR: u32 = 0x040;
pub const TIOCM_RNG: u32 = 0x080;
pub const TIOCM_DSR: u32 = 0x100;
pub const TIOCM_CD: u32 = TIOCM_CAR;
pub const TIOCM_RI: u32 = TIOCM_RNG;
pub const TIOCM_OUT1: u32 = 0x2000;
pub const TIOCM_OUT2: u32 = 0x4000;
pub const TIOCM_LOOP: u32 = 0x8000;
pub const TIOCM_LE: c_ulong = 0x001;
pub const TIOCM_DTR: c_ulong = 0x002;
pub const TIOCM_RTS: c_ulong = 0x004;
pub const TIOCM_ST: c_ulong = 0x008;
pub const TIOCM_SR: c_ulong = 0x010;
pub const TIOCM_CTS: c_ulong = 0x020;
pub const TIOCM_CAR: c_ulong = 0x040;
pub const TIOCM_RNG: c_ulong = 0x080;
pub const TIOCM_DSR: c_ulong = 0x100;
pub const TIOCM_CD: c_ulong = TIOCM_CAR;
pub const TIOCM_RI: c_ulong = TIOCM_RNG;
pub const TIOCM_OUT1: c_ulong = 0x2000;
pub const TIOCM_OUT2: c_ulong = 0x4000;
pub const TIOCM_LOOP: c_ulong = 0x8000;
pub const N_TTY: u32 = 0;
pub const N_SLIP: u32 = 1;
pub const N_MOUSE: u32 = 2;
pub const N_PPP: u32 = 3;
pub const N_STRIP: u32 = 4;
pub const N_AX25: u32 = 5;
pub const N_X25: u32 = 6;
pub const N_6PACK: u32 = 7;
pub const N_MASC: u32 = 8;
pub const N_R3964: u32 = 9;
pub const N_PROFIBUS_FDL: u32 = 10;
pub const N_IRDA: u32 = 11;
pub const N_SMSBLOCK: u32 = 12;
pub const N_HDLC: u32 = 13;
pub const N_SYNC_PPP: u32 = 14;
pub const N_HCI: u32 = 15;
pub const N_TTY: c_ulong = 0;
pub const N_SLIP: c_ulong = 1;
pub const N_MOUSE: c_ulong = 2;
pub const N_PPP: c_ulong = 3;
pub const N_STRIP: c_ulong = 4;
pub const N_AX25: c_ulong = 5;
pub const N_X25: c_ulong = 6;
pub const N_6PACK: c_ulong = 7;
pub const N_MASC: c_ulong = 8;
pub const N_R3964: c_ulong = 9;
pub const N_PROFIBUS_FDL: c_ulong = 10;
pub const N_IRDA: c_ulong = 11;
pub const N_SMSBLOCK: c_ulong = 12;
pub const N_HDLC: c_ulong = 13;
pub const N_SYNC_PPP: c_ulong = 14;
pub const N_HCI: c_ulong = 15;
pub const FIOSETOWN: u32 = 0x8901;
pub const SIOCSPGRP: u32 = 0x8902;
pub const FIOGETOWN: u32 = 0x8903;
pub const SIOCGPGRP: u32 = 0x8904;
pub const SIOCATMARK: u32 = 0x8905;
pub const SIOCGSTAMP: u32 = 0x8906;
pub const SIOCGSTAMPNS: u32 = 0x8907;
pub const FIOSETOWN: c_ulong = 0x8901;
pub const SIOCSPGRP: c_ulong = 0x8902;
pub const FIOGETOWN: c_ulong = 0x8903;
pub const SIOCGPGRP: c_ulong = 0x8904;
pub const SIOCATMARK: c_ulong = 0x8905;
pub const SIOCGSTAMP: c_ulong = 0x8906;
pub const SIOCGSTAMPNS: c_ulong = 0x8907;
pub const SIOCADDRT: u32 = 0x890B;
pub const SIOCDELRT: u32 = 0x890C;
pub const SIOCRTMSG: u32 = 0x890D;
pub const SIOCADDRT: c_ulong = 0x890B;
pub const SIOCDELRT: c_ulong = 0x890C;
pub const SIOCRTMSG: c_ulong = 0x890D;
pub const SIOCGIFNAME: u32 = 0x8910;
pub const SIOCSIFLINK: u32 = 0x8911;
pub const SIOCGIFCONF: u32 = 0x8912;
pub const SIOCGIFFLAGS: u32 = 0x8913;
pub const SIOCSIFFLAGS: u32 = 0x8914;
pub const SIOCGIFADDR: u32 = 0x8915;
pub const SIOCSIFADDR: u32 = 0x8916;
pub const SIOCGIFDSTADDR: u32 = 0x8917;
pub const SIOCSIFDSTADDR: u32 = 0x8918;
pub const SIOCGIFBRDADDR: u32 = 0x8919;
pub const SIOCSIFBRDADDR: u32 = 0x891a;
pub const SIOCGIFNETMASK: u32 = 0x891b;
pub const SIOCSIFNETMASK: u32 = 0x891c;
pub const SIOCGIFMETRIC: u32 = 0x891d;
pub const SIOCSIFMETRIC: u32 = 0x891e;
pub const SIOCGIFMEM: u32 = 0x891f;
pub const SIOCSIFMEM: u32 = 0x8920;
pub const SIOCGIFMTU: u32 = 0x8921;
pub const SIOCSIFMTU: u32 = 0x8922;
pub const SIOCSIFNAME: u32 = 0x8923;
pub const SIOCSIFHWADDR: u32 = 0x8924;
pub const SIOCGIFENCAP: u32 = 0x8925;
pub const SIOCSIFENCAP: u32 = 0x8926;
pub const SIOCGIFHWADDR: u32 = 0x8927;
pub const SIOCGIFSLAVE: u32 = 0x8929;
pub const SIOCSIFSLAVE: u32 = 0x8930;
pub const SIOCADDMULTI: u32 = 0x8931;
pub const SIOCDELMULTI: u32 = 0x8932;
pub const SIOCGIFINDEX: u32 = 0x8933;
pub const SIOGIFINDEX: u32 = SIOCGIFINDEX;
pub const SIOCSIFPFLAGS: u32 = 0x8934;
pub const SIOCGIFPFLAGS: u32 = 0x8935;
pub const SIOCDIFADDR: u32 = 0x8936;
pub const SIOCSIFHWBROADCAST: u32 = 0x8937;
pub const SIOCGIFCOUNT: u32 = 0x8938;
pub const SIOCGIFNAME: c_ulong = 0x8910;
pub const SIOCSIFLINK: c_ulong = 0x8911;
pub const SIOCGIFCONF: c_ulong = 0x8912;
pub const SIOCGIFFLAGS: c_ulong = 0x8913;
pub const SIOCSIFFLAGS: c_ulong = 0x8914;
pub const SIOCGIFADDR: c_ulong = 0x8915;
pub const SIOCSIFADDR: c_ulong = 0x8916;
pub const SIOCGIFDSTADDR: c_ulong = 0x8917;
pub const SIOCSIFDSTADDR: c_ulong = 0x8918;
pub const SIOCGIFBRDADDR: c_ulong = 0x8919;
pub const SIOCSIFBRDADDR: c_ulong = 0x891a;
pub const SIOCGIFNETMASK: c_ulong = 0x891b;
pub const SIOCSIFNETMASK: c_ulong = 0x891c;
pub const SIOCGIFMETRIC: c_ulong = 0x891d;
pub const SIOCSIFMETRIC: c_ulong = 0x891e;
pub const SIOCGIFMEM: c_ulong = 0x891f;
pub const SIOCSIFMEM: c_ulong = 0x8920;
pub const SIOCGIFMTU: c_ulong = 0x8921;
pub const SIOCSIFMTU: c_ulong = 0x8922;
pub const SIOCSIFNAME: c_ulong = 0x8923;
pub const SIOCSIFHWADDR: c_ulong = 0x8924;
pub const SIOCGIFENCAP: c_ulong = 0x8925;
pub const SIOCSIFENCAP: c_ulong = 0x8926;
pub const SIOCGIFHWADDR: c_ulong = 0x8927;
pub const SIOCGIFSLAVE: c_ulong = 0x8929;
pub const SIOCSIFSLAVE: c_ulong = 0x8930;
pub const SIOCADDMULTI: c_ulong = 0x8931;
pub const SIOCDELMULTI: c_ulong = 0x8932;
pub const SIOCGIFINDEX: c_ulong = 0x8933;
pub const SIOGIFINDEX: c_ulong = SIOCGIFINDEX;
pub const SIOCSIFPFLAGS: c_ulong = 0x8934;
pub const SIOCGIFPFLAGS: c_ulong = 0x8935;
pub const SIOCDIFADDR: c_ulong = 0x8936;
pub const SIOCSIFHWBROADCAST: c_ulong = 0x8937;
pub const SIOCGIFCOUNT: c_ulong = 0x8938;
pub const SIOCGIFBR: u32 = 0x8940;
pub const SIOCSIFBR: u32 = 0x8941;
pub const SIOCGIFBR: c_ulong = 0x8940;
pub const SIOCSIFBR: c_ulong = 0x8941;
pub const SIOCGIFTXQLEN: u32 = 0x8942;
pub const SIOCSIFTXQLEN: u32 = 0x8943;
pub const SIOCGIFTXQLEN: c_ulong = 0x8942;
pub const SIOCSIFTXQLEN: c_ulong = 0x8943;
pub const SIOCDARP: u32 = 0x8953;
pub const SIOCGARP: u32 = 0x8954;
pub const SIOCSARP: u32 = 0x8955;
pub const SIOCDARP: c_ulong = 0x8953;
pub const SIOCGARP: c_ulong = 0x8954;
pub const SIOCSARP: c_ulong = 0x8955;
pub const SIOCDRARP: u32 = 0x8960;
pub const SIOCGRARP: u32 = 0x8961;
pub const SIOCSRARP: u32 = 0x8962;
pub const SIOCDRARP: c_ulong = 0x8960;
pub const SIOCGRARP: c_ulong = 0x8961;
pub const SIOCSRARP: c_ulong = 0x8962;
pub const SIOCGIFMAP: u32 = 0x8970;
pub const SIOCSIFMAP: u32 = 0x8971;
pub const SIOCGIFMAP: c_ulong = 0x8970;
pub const SIOCSIFMAP: c_ulong = 0x8971;
pub const SIOCADDDLCI: u32 = 0x8980;
pub const SIOCDELDLCI: u32 = 0x8981;
pub const SIOCADDDLCI: c_ulong = 0x8980;
pub const SIOCDELDLCI: c_ulong = 0x8981;
pub const SIOCDEVPRIVATE: u32 = 0x89F0;
pub const SIOCPROTOPRIVATE: u32 = 0x89E0;
pub const SIOCDEVPRIVATE: c_ulong = 0x89F0;
pub const SIOCPROTOPRIVATE: c_ulong = 0x89E0;
}
#[cfg(target_os = "linux")]
+14 -4
View File
@@ -6,7 +6,12 @@ extern crate platform;
use platform::types::*;
pub const ITIMER_REAL: c_int = 0;
pub const ITIMER_VIRTUAL: c_int = 1;
pub const ITIMER_PROF: c_int = 2;
#[repr(C)]
#[derive(Default)]
pub struct timeval {
pub tv_sec: time_t,
pub tv_usec: suseconds_t,
@@ -18,6 +23,7 @@ pub struct timezone {
}
#[repr(C)]
#[derive(Default)]
pub struct itimerval {
pub it_interval: timeval,
pub it_value: timeval,
@@ -28,18 +34,22 @@ pub struct fd_set {
pub fds_bits: [c_long; 16usize],
}
// #[no_mangle]
#[no_mangle]
pub extern "C" fn getitimer(which: c_int, value: *mut itimerval) -> c_int {
unimplemented!();
platform::getitimer(which, value as *mut platform::types::itimerval)
}
// #[no_mangle]
#[no_mangle]
pub extern "C" fn setitimer(
which: c_int,
value: *const itimerval,
ovalue: *mut itimerval,
) -> c_int {
unimplemented!();
platform::setitimer(
which,
value as *const platform::types::itimerval,
ovalue as *mut platform::types::itimerval
)
}
#[no_mangle]
+1 -1
View File
@@ -12,4 +12,4 @@ errno = { path = "../errno" }
platform = { path = "../platform" }
stdio = { path = "../stdio" }
string = { path = "../string" }
sys_ioctl = { path = "../sys_ioctl" }
sys_time = { path = "../sys_time" }
+43 -5
View File
@@ -6,6 +6,7 @@ extern crate errno;
extern crate platform;
extern crate stdio;
extern crate string;
extern crate sys_time;
use core::{ptr, slice};
@@ -47,9 +48,26 @@ pub extern "C" fn access(path: *const c_char, amode: c_int) -> c_int {
unimplemented!();
}
// #[no_mangle]
#[no_mangle]
pub extern "C" fn alarm(seconds: c_uint) -> c_uint {
unimplemented!();
let mut timer = sys_time::itimerval {
it_value: sys_time::timeval {
tv_sec: seconds as time_t,
tv_usec: 0
},
..Default::default()
};
let errno_backup = unsafe { platform::errno };
let secs = if sys_time::setitimer(sys_time::ITIMER_REAL, &timer, &mut timer) < 0 {
0
} else {
timer.it_value.tv_sec as c_uint + if timer.it_value.tv_usec > 0 { 1 } else { 0 }
};
unsafe {
platform::errno = errno_backup;
}
secs
}
#[no_mangle]
@@ -432,9 +450,29 @@ pub extern "C" fn ttyname_r(fildes: c_int, name: *mut c_char, namesize: size_t)
unimplemented!();
}
// #[no_mangle]
pub extern "C" fn ualarm(useconds: useconds_t, interval: useconds_t) -> useconds_t {
unimplemented!();
#[no_mangle]
pub extern "C" fn ualarm(value: useconds_t, interval: useconds_t) -> useconds_t {
let mut timer = sys_time::itimerval {
it_value: sys_time::timeval {
tv_sec: 0,
tv_usec: value as suseconds_t
},
it_interval: sys_time::timeval {
tv_sec: 0,
tv_usec: interval as suseconds_t
}
};
let errno_backup = unsafe { platform::errno };
let usecs = if sys_time::setitimer(sys_time::ITIMER_REAL, &timer, &mut timer) < 0 {
0
} else {
timer.it_value.tv_sec as useconds_t * 1_000_000 + timer.it_value.tv_usec as useconds_t
};
unsafe {
platform::errno = errno_backup;
}
usecs
}
#[no_mangle]