mod.rs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //! sys/time implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/systime.h.html
  2. use crate::c_str::CStr;
  3. use crate::header::time::timespec;
  4. use crate::platform::types::*;
  5. use crate::platform::{Pal, PalSignal, Sys};
  6. pub const ITIMER_REAL: c_int = 0;
  7. pub const ITIMER_VIRTUAL: c_int = 1;
  8. pub const ITIMER_PROF: c_int = 2;
  9. #[repr(C)]
  10. #[derive(Default)]
  11. pub struct timeval {
  12. pub tv_sec: time_t,
  13. pub tv_usec: suseconds_t,
  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. #[repr(C)]
  22. #[derive(Default)]
  23. pub struct itimerval {
  24. pub it_interval: timeval,
  25. pub it_value: timeval,
  26. }
  27. #[repr(C)]
  28. pub struct fd_set {
  29. pub fds_bits: [c_long; 16usize],
  30. }
  31. #[no_mangle]
  32. pub extern "C" fn getitimer(which: c_int, value: *mut itimerval) -> c_int {
  33. Sys::getitimer(which, value)
  34. }
  35. #[no_mangle]
  36. pub extern "C" fn setitimer(
  37. which: c_int,
  38. value: *const itimerval,
  39. ovalue: *mut itimerval,
  40. ) -> c_int {
  41. Sys::setitimer(which, value, ovalue)
  42. }
  43. #[no_mangle]
  44. pub extern "C" fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int {
  45. Sys::gettimeofday(tp, tzp)
  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 i64) * 1000,
  54. },
  55. timespec {
  56. tv_sec: (*times.offset(1)).tv_sec,
  57. tv_nsec: ((*times.offset(1)).tv_usec as i64) * 1000,
  58. },
  59. ];
  60. Sys::utimens(path, times_spec.as_ptr())
  61. }