1 //! This module roughly corresponds to `mach/clock_types.h`.
2 
3 pub type alarm_type_t = ::libc::c_int;
4 pub type sleep_type_t = ::libc::c_int;
5 pub type clock_id_t = ::libc::c_int;
6 pub type clock_flavor_t = ::libc::c_int;
7 pub type clock_attr_t = *mut ::libc::c_int;
8 pub type clock_res_t = ::libc::c_int;
9 
10 #[repr(C)]
11 #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
12 pub struct mach_timespec {
13     pub tv_sec: ::libc::c_uint,
14     pub tv_nsec: clock_res_t,
15 }
16 pub type mach_timespec_t = mach_timespec;
17 
18 pub const SYSTEM_CLOCK: ::libc::c_uint = 0;
19 pub const CALENDAR_CLOCK: ::libc::c_uint = 1;
20 pub const REALTIME_CLOCK: ::libc::c_uint = 0;
21 
22 pub const CLOCK_GET_TIME_RES: ::libc::c_uint = 1;
23 pub const CLOCK_ALARM_CURRES: ::libc::c_uint = 3;
24 pub const CLOCK_ALARM_MINRES: ::libc::c_uint = 4;
25 pub const CLOCK_ALARM_MAXRES: ::libc::c_uint = 5;
26 
27 pub const NSEC_PER_USEC: ::libc::c_ulonglong = 1000;
28 pub const USEC_PER_SEC: ::libc::c_ulonglong = 1_000_000;
29 pub const NSEC_PER_SEC: ::libc::c_ulonglong = 1_000_000_000;
30 pub const NSEC_PER_MSEC: ::libc::c_ulonglong = 1_000_000;
31 
32 #[allow(non_snake_case)]
BAD_MACH_TIMESPEC(t: mach_timespec) -> bool33 pub fn BAD_MACH_TIMESPEC(t: mach_timespec) -> bool {
34     t.tv_nsec < 0 || (t.tv_nsec as ::libc::c_ulonglong) >= NSEC_PER_SEC
35 }
36 
37 #[allow(non_snake_case)]
CMP_MACH_TIMESPEC(t1: &mach_timespec, t2: &mach_timespec) -> ::libc::c_ulonglong38 pub fn CMP_MACH_TIMESPEC(t1: &mach_timespec, t2: &mach_timespec) -> ::libc::c_ulonglong {
39     if t1.tv_sec > t2.tv_sec {
40         return NSEC_PER_SEC;
41     }
42     if t1.tv_sec < t2.tv_sec {
43         return !NSEC_PER_SEC;
44     }
45     (t1.tv_nsec as ::libc::c_ulonglong) - (t2.tv_nsec as ::libc::c_ulonglong)
46 }
47 
48 #[allow(non_snake_case)]
ADD_MACH_TIMESPEC(t1: &mut mach_timespec, t2: &mach_timespec)49 pub fn ADD_MACH_TIMESPEC(t1: &mut mach_timespec, t2: &mach_timespec) {
50     t1.tv_nsec += t2.tv_nsec;
51     if (t1.tv_nsec as ::libc::c_ulonglong) >= NSEC_PER_SEC {
52         t1.tv_nsec = (t1.tv_nsec as ::libc::c_ulonglong - NSEC_PER_SEC) as clock_res_t;
53         t1.tv_sec += 1;
54     }
55     t1.tv_sec += t2.tv_sec;
56 }
57 
58 #[allow(non_snake_case)]
SUB_MACH_TIMESPEC(t1: &mut mach_timespec, t2: &mach_timespec)59 pub fn SUB_MACH_TIMESPEC(t1: &mut mach_timespec, t2: &mach_timespec) {
60     t1.tv_nsec -= t2.tv_nsec;
61     if t1.tv_nsec < 0 {
62         t1.tv_nsec = (t1.tv_nsec as ::libc::c_ulonglong + NSEC_PER_SEC) as clock_res_t;
63         t1.tv_sec -= 1;
64     }
65     t1.tv_sec -= t2.tv_sec;
66 }
67 
68 pub const ALRMTYPE: ::libc::c_uint = 0xff;
69 pub const TIME_ABSOLUTE: ::libc::c_uint = 0x00;
70 pub const TIME_RELATIVE: ::libc::c_uint = 0x01;
71 
72 #[allow(non_snake_case)]
BAD_ALRMTYPE(t: ::libc::c_uint) -> bool73 pub fn BAD_ALRMTYPE(t: ::libc::c_uint) -> bool {
74     t & (!TIME_RELATIVE) != 0
75 }
76