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