Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
google
GitHub Repository: google/crosvm
Path: blob/main/base/src/sys/unix/time.rs
5394 views
1
// Copyright 2024 The ChromiumOS Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
use std::time::Duration;
6
7
use libc::timespec;
8
9
/// Return a timespec filed with the specified Duration `duration`.
10
#[allow(clippy::useless_conversion)]
11
pub fn duration_to_timespec(duration: Duration) -> timespec {
12
// nsec always fits in i32 because subsec_nanos is defined to be less than one billion.
13
let nsec = duration.subsec_nanos() as i32;
14
timespec {
15
tv_sec: duration.as_secs() as libc::time_t,
16
tv_nsec: nsec.into(),
17
}
18
}
19
20