/src/crosvm/base/src/sys/unix/time.rs
Line | Count | Source (jump to first uncovered line) |
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 | 0 | pub fn duration_to_timespec(duration: Duration) -> timespec { |
12 | 0 | // nsec always fits in i32 because subsec_nanos is defined to be less than one billion. |
13 | 0 | let nsec = duration.subsec_nanos() as i32; |
14 | 0 | timespec { |
15 | 0 | tv_sec: duration.as_secs() as libc::time_t, |
16 | 0 | tv_nsec: nsec.into(), |
17 | 0 | } |
18 | 0 | } |