Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update use of libc::timespec to prepare for future libc version #528

Merged
merged 1 commit into from
Nov 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,19 +512,22 @@ mod inner {
mod unix {
use std::fmt;
use std::cmp::Ordering;
use std::mem::zeroed;
use std::ops::{Add, Sub};
use libc;

use Duration;

pub fn get_time() -> (i64, i32) {
let mut tv = libc::timespec { tv_sec: 0, tv_nsec: 0 };
// SAFETY: libc::timespec is zero initializable.
let mut tv: libc::timespec = unsafe { zeroed() };
unsafe { libc::clock_gettime(libc::CLOCK_REALTIME, &mut tv); }
(tv.tv_sec as i64, tv.tv_nsec as i32)
}

pub fn get_precise_ns() -> u64 {
let mut ts = libc::timespec { tv_sec: 0, tv_nsec: 0 };
// SAFETY: libc::timespec is zero initializable.
let mut ts: libc::timespec = unsafe { zeroed() };
unsafe {
libc::clock_gettime(libc::CLOCK_MONOTONIC, &mut ts);
}
Expand Down Expand Up @@ -552,10 +555,8 @@ mod inner {
impl SteadyTime {
pub fn now() -> SteadyTime {
let mut t = SteadyTime {
t: libc::timespec {
tv_sec: 0,
tv_nsec: 0,
}
// SAFETY: libc::timespec is zero initializable.
t: unsafe { zeroed() }
};
unsafe {
assert_eq!(0, libc::clock_gettime(libc::CLOCK_MONOTONIC,
Expand Down