diff options
author | Geert-Jan Zwiers <geertjanzwiers@protonmail.com> | 2023-01-03 21:04:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-03 15:04:02 -0500 |
commit | deed07e1d9f103d9829164f03436bd4852ee42e5 (patch) | |
tree | 351bb02e69d6bf92842fef10264e9df4b70d700d /runtime/ops/os/sys_info.rs | |
parent | c1ffd3d2cb94b94aa427316b834dc3df03eea0ce (diff) |
chore: resolve clippy errors in windows build (#17215)
Diffstat (limited to 'runtime/ops/os/sys_info.rs')
-rw-r--r-- | runtime/ops/os/sys_info.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/runtime/ops/os/sys_info.rs b/runtime/ops/os/sys_info.rs index 06807a8ea..366864f46 100644 --- a/runtime/ops/os/sys_info.rs +++ b/runtime/ops/os/sys_info.rs @@ -302,17 +302,19 @@ pub fn mem_info() -> Option<MemInfo> { } pub fn os_uptime() -> u64 { - let mut uptime: u64 = 0; + let uptime: u64; #[cfg(target_os = "linux")] { let mut info = std::mem::MaybeUninit::uninit(); // SAFETY: `info` is a valid pointer to a `libc::sysinfo` struct. let res = unsafe { libc::sysinfo(info.as_mut_ptr()) }; - if res == 0 { + uptime = if res == 0 { // SAFETY: `sysinfo` initializes the struct. let info = unsafe { info.assume_init() }; - uptime = info.uptime as u64; + info.uptime as u64 + } else { + 0 } } @@ -341,8 +343,8 @@ pub fn os_uptime() -> u64 { 0, ) }; - if res == 0 { - uptime = SystemTime::now() + uptime = if res == 0 { + SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .map(|d| { (d - Duration::new( @@ -351,15 +353,18 @@ pub fn os_uptime() -> u64 { )) .as_secs() }) - .unwrap_or_default(); + .unwrap_or_default() + } else { + 0 } } #[cfg(target_family = "windows")] + // SAFETY: windows API usage unsafe { // Windows is the only one that returns `uptime` in milisecond precision, // so we need to get the seconds out of it to be in sync with other envs. - uptime = winapi::um::sysinfoapi::GetTickCount64() as u64 / 1000; + uptime = winapi::um::sysinfoapi::GetTickCount64() / 1000; } uptime |