lib.rs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. //! time implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/time.h.html
  2. #![no_std]
  3. extern crate platform;
  4. use platform::types::*;
  5. #[cfg(target_os = "redox")]
  6. pub const CLOCK_REALTIME: c_int = 1;
  7. #[cfg(target_os = "redox")]
  8. pub const CLOCK_MONOTONIC: c_int = 4;
  9. #[cfg(target_os = "linux")]
  10. pub const CLOCK_REALTIME: c_int = 0;
  11. #[cfg(target_os = "linux")]
  12. pub const CLOCK_MONOTONIC: c_int = 1;
  13. #[cfg(target_os = "linux")]
  14. pub const CLOCK_PROCESS_CPUTIME_ID: c_int = 2;
  15. #[cfg(target_os = "linux")]
  16. pub const CLOCK_THREAD_CPUTIME_ID: c_int = 3;
  17. #[cfg(target_os = "linux")]
  18. pub const CLOCK_MONOTONIC_RAW: c_int = 4;
  19. #[cfg(target_os = "linux")]
  20. pub const CLOCK_REALTIME_COARSE: c_int = 5;
  21. #[cfg(target_os = "linux")]
  22. pub const CLOCK_MONOTONIC_COARSE: c_int = 6;
  23. #[cfg(target_os = "linux")]
  24. pub const CLOCK_BOOTTIME: c_int = 7;
  25. #[cfg(target_os = "linux")]
  26. pub const CLOCK_REALTIME_ALARM: c_int = 8;
  27. #[cfg(target_os = "linux")]
  28. pub const CLOCK_BOOTTIME_ALARM: c_int = 9;
  29. #[cfg(target_os = "linux")]
  30. pub const CLOCK_TAI: c_int = 11;
  31. /*
  32. *#[repr(C)]
  33. *pub struct timespec {
  34. * pub tv_sec: time_t,
  35. * pub tv_nsec: c_long,
  36. *}
  37. */
  38. #[repr(C)]
  39. pub struct tm {
  40. pub tm_sec: c_int,
  41. pub tm_min: c_int,
  42. pub tm_hour: c_int,
  43. pub tm_mday: c_int,
  44. pub tm_mon: c_int,
  45. pub tm_year: c_int,
  46. pub tm_wday: c_int,
  47. pub tm_yday: c_int,
  48. pub tm_isdst: c_int,
  49. pub tm_gmtoff: c_long,
  50. pub tm_zone: *const c_char,
  51. }
  52. #[repr(C)]
  53. pub struct itimerspec {
  54. pub it_interval: timespec,
  55. pub it_value: timespec,
  56. }
  57. pub struct sigevent;
  58. #[no_mangle]
  59. pub extern "C" fn asctime(timeptr: *const tm) -> *mut c_char {
  60. unimplemented!();
  61. }
  62. #[no_mangle]
  63. pub extern "C" fn asctime_r(tm: *const tm, buf: *mut c_char) -> *mut c_char {
  64. unimplemented!();
  65. }
  66. #[no_mangle]
  67. pub extern "C" fn clock() -> clock_t {
  68. unimplemented!();
  69. }
  70. #[no_mangle]
  71. pub extern "C" fn clock_getres(clock_id: clockid_t, res: *mut timespec) -> c_int {
  72. unimplemented!();
  73. }
  74. #[no_mangle]
  75. pub extern "C" fn clock_gettime(clock_id: clockid_t, tp: *mut timespec) -> c_int {
  76. platform::clock_gettime(clock_id, tp)
  77. }
  78. #[no_mangle]
  79. pub extern "C" fn clock_settime(clock_id: clockid_t, tp: *const timespec) -> c_int {
  80. unimplemented!();
  81. }
  82. #[no_mangle]
  83. pub extern "C" fn ctime(clock: *const time_t) -> *mut c_char {
  84. unimplemented!();
  85. }
  86. #[no_mangle]
  87. pub extern "C" fn ctime_r(clock: *const time_t, buf: *mut c_char) -> *mut c_char {
  88. unimplemented!();
  89. }
  90. #[no_mangle]
  91. pub extern "C" fn difftime(time1: time_t, time0: time_t) -> f64 {
  92. unimplemented!();
  93. }
  94. #[no_mangle]
  95. pub extern "C" fn getdate(string: *const c_char) -> tm {
  96. unimplemented!();
  97. }
  98. #[no_mangle]
  99. pub extern "C" fn gmtime(timer: *const time_t) -> *mut tm {
  100. unimplemented!();
  101. }
  102. #[no_mangle]
  103. pub extern "C" fn gmtime_r(clock: *const time_t, result: *mut tm) -> *mut tm {
  104. unimplemented!();
  105. }
  106. #[no_mangle]
  107. pub extern "C" fn localtime(timer: *const time_t) -> *mut tm {
  108. unimplemented!();
  109. }
  110. #[no_mangle]
  111. pub extern "C" fn localtime_r(clock: *const time_t, result: *mut tm) -> *mut tm {
  112. unimplemented!();
  113. }
  114. #[no_mangle]
  115. pub extern "C" fn mktime(timeptr: *mut tm) -> time_t {
  116. unimplemented!();
  117. }
  118. #[no_mangle]
  119. pub extern "C" fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int {
  120. platform::nanosleep(rqtp, rmtp)
  121. }
  122. #[no_mangle]
  123. pub extern "C" fn strftime(
  124. s: *mut c_char,
  125. maxsize: usize,
  126. format: *const c_char,
  127. timptr: *const tm,
  128. ) -> usize {
  129. unimplemented!();
  130. }
  131. #[no_mangle]
  132. pub extern "C" fn strptime(buf: *const c_char, format: *const c_char, tm: *mut tm) -> *mut c_char {
  133. unimplemented!();
  134. }
  135. #[no_mangle]
  136. pub extern "C" fn time(tloc: *mut time_t) -> time_t {
  137. let mut ts: timespec = Default::default();
  138. platform::clock_gettime(CLOCK_REALTIME, &mut ts);
  139. unsafe {
  140. if !tloc.is_null() {
  141. *tloc = ts.tv_sec
  142. };
  143. }
  144. ts.tv_sec
  145. }
  146. #[no_mangle]
  147. pub extern "C" fn timer_create(
  148. clock_id: clockid_t,
  149. evp: *mut sigevent,
  150. timerid: *mut timer_t,
  151. ) -> c_int {
  152. unimplemented!();
  153. }
  154. #[no_mangle]
  155. pub extern "C" fn timer_delete(timerid: timer_t) -> c_int {
  156. unimplemented!();
  157. }
  158. #[no_mangle]
  159. pub extern "C" fn tzset() {
  160. unimplemented!();
  161. }
  162. #[no_mangle]
  163. pub extern "C" fn timer_settime(
  164. timerid: timer_t,
  165. flags: c_int,
  166. value: *const itimerspec,
  167. ovalue: *mut itimerspec,
  168. ) -> c_int {
  169. unimplemented!();
  170. }
  171. #[no_mangle]
  172. pub extern "C" fn timer_gettime(timerid: timer_t, value: *mut itimerspec) -> c_int {
  173. unimplemented!();
  174. }
  175. #[no_mangle]
  176. pub extern "C" fn timer_getoverrun(timerid: timer_t) -> c_int {
  177. unimplemented!();
  178. }
  179. /*
  180. #[no_mangle]
  181. pub extern "C" fn func(args) -> c_int {
  182. unimplemented!();
  183. }
  184. */