1extern crate c2rust_bitfields;
2extern crate libc;
3extern crate core;
4extern "C" {
5 fn snprintf(
6 _: *mut libc::c_char,
7 _: libc::c_ulong,
8 _: *const libc::c_char,
9 _: ...
10 ) -> libc::c_int;
11 fn clock_gettime(__clock_id: clockid_t, __tp: *mut timespec) -> libc::c_int;
12 fn __assert_fail(
13 __assertion: *const libc::c_char,
14 __file: *const libc::c_char,
15 __line: libc::c_uint,
16 __function: *const libc::c_char,
17 ) -> !;
18}
19pub type __uint64_t = libc::c_ulong;
20pub type __time_t = libc::c_long;
21pub type __clockid_t = libc::c_int;
22pub type __syscall_slong_t = libc::c_long;
23pub type uint64_t = __uint64_t;
24pub type monotime = uint64_t;
25pub type monotonic_clock_type = libc::c_uint;
26pub const MONOTONIC_CLOCK_HW: monotonic_clock_type = 1;
27pub const MONOTONIC_CLOCK_POSIX: monotonic_clock_type = 0;
28#[derive(Copy, Clone)]
29#[repr(C)]
30pub struct timespec {
31 pub tv_sec: __time_t,
32 pub tv_nsec: __syscall_slong_t,
33}
34pub type clockid_t = __clockid_t;
35#[no_mangle]
36pub static mut getMonotonicUs: Option::<unsafe extern "C" fn() -> monotime> = None;
37static mut monotonic_info_string: [libc::c_char; 32] = [0; 32];
38unsafe extern "C" fn getMonotonicUs_posix() -> monotime {
39 let mut ts: timespec = timespec { tv_sec: 0, tv_nsec: 0 };
40 clock_gettime(1 as libc::c_int, &mut ts);
41 return (ts.tv_sec as uint64_t)
42 .wrapping_mul(1000000 as libc::c_int as libc::c_ulong)
43 .wrapping_add(
44 (ts.tv_nsec / 1000 as libc::c_int as libc::c_long) as libc::c_ulong,
45 );
46}
47unsafe extern "C" fn monotonicInit_posix() {
48 let mut ts: timespec = timespec { tv_sec: 0, tv_nsec: 0 };
49 let mut rc: libc::c_int = clock_gettime(1 as libc::c_int, &mut ts);
50 if rc == 0 as libc::c_int {} else {
51 println!("RC = {}", rc.to_string());
52 __assert_fail(
53 b"rc == 0\0" as *const u8 as *const libc::c_char,
54 b"monotonic.c\0" as *const u8 as *const libc::c_char,
55 149 as libc::c_int as libc::c_uint,
56 (*core::mem::transmute::<
57 &[u8; 27],
58 &[libc::c_char; 27],
59 >(b"void monotonicInit_posix()\0"))
60 .as_ptr(),
61 );
62 };
63 snprintf(
64 monotonic_info_string.as_mut_ptr(),
65 core::mem::size_of::<[libc::c_char; 32]>() as libc::c_ulong,
66 b"POSIX clock_gettime\0" as *const u8 as *const libc::c_char,
67 );
68 getMonotonicUs = core::mem::transmute::<
69 Option::<unsafe extern "C" fn() -> monotime>,
70 Option::<unsafe extern "C" fn() -> monotime>,
71 >(
72 Some(
73 core::mem::transmute::<
74 unsafe extern "C" fn() -> monotime,
75 unsafe extern "C" fn() -> monotime,
76 >(getMonotonicUs_posix),
77 ),
78 );
79}
80#[no_mangle]
81pub unsafe extern "C" fn monotonicInit() -> *const libc::c_char {
82 if getMonotonicUs.is_none() {
83 monotonicInit_posix();
84 }
85 return monotonic_info_string.as_mut_ptr();
86}
87#[no_mangle]
88pub unsafe extern "C" fn monotonicInfoString() -> *const libc::c_char {
89 return monotonic_info_string.as_mut_ptr();
90}
91#[no_mangle]
92pub unsafe extern "C" fn monotonicGetType() -> monotonic_clock_type {
93 if getMonotonicUs
94 == core::mem::transmute::<
95 Option::<unsafe extern "C" fn() -> monotime>,
96 Option::<unsafe extern "C" fn() -> monotime>,
97 >(
98 Some(
99 core::mem::transmute::<
100 unsafe extern "C" fn() -> monotime,
101 unsafe extern "C" fn() -> monotime,
102 >(getMonotonicUs_posix),
103 ),
104 )
105 {
106 return MONOTONIC_CLOCK_POSIX;
107 }
108 return MONOTONIC_CLOCK_HW;
109}