1 //! sys/time implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/systime.h.html 2 3 use crate::{ 4 c_str::CStr, 5 header::time::timespec, 6 platform::{types::*, Pal, PalSignal, Sys}, 7 }; 8 9 pub const ITIMER_REAL: c_int = 0; 10 pub const ITIMER_VIRTUAL: c_int = 1; 11 pub const ITIMER_PROF: c_int = 2; 12 13 #[repr(C)] 14 #[derive(Default)] 15 pub struct timeval { 16 pub tv_sec: time_t, 17 pub tv_usec: suseconds_t, 18 } 19 #[repr(C)] 20 #[derive(Default)] 21 pub struct timezone { 22 pub tz_minuteswest: c_int, 23 pub tz_dsttime: c_int, 24 } 25 26 #[repr(C)] 27 #[derive(Default)] 28 pub struct itimerval { 29 pub it_interval: timeval, 30 pub it_value: timeval, 31 } 32 33 #[repr(C)] 34 pub struct fd_set { 35 pub fds_bits: [c_long; 16usize], 36 } 37 38 #[no_mangle] 39 pub extern "C" fn getitimer(which: c_int, value: *mut itimerval) -> c_int { 40 Sys::getitimer(which, value) 41 } 42 43 #[no_mangle] 44 pub extern "C" fn setitimer( 45 which: c_int, 46 value: *const itimerval, 47 ovalue: *mut itimerval, 48 ) -> c_int { 49 Sys::setitimer(which, value, ovalue) 50 } 51 52 #[no_mangle] 53 pub extern "C" fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int { 54 Sys::gettimeofday(tp, tzp) 55 } 56 57 #[no_mangle] 58 pub unsafe extern "C" fn utimes(path: *const c_char, times: *const timeval) -> c_int { 59 let path = CStr::from_ptr(path); 60 let times_spec = [ 61 timespec { 62 tv_sec: (*times.offset(0)).tv_sec, 63 tv_nsec: ((*times.offset(0)).tv_usec as c_long) * 1000, 64 }, 65 timespec { 66 tv_sec: (*times.offset(1)).tv_sec, 67 tv_nsec: ((*times.offset(1)).tv_usec as c_long) * 1000, 68 }, 69 ]; 70 Sys::utimens(path, times_spec.as_ptr()) 71 } 72