We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 88c9ff5 commit 0233cdcCopy full SHA for 0233cdc
src/uptime.rs
@@ -1,12 +1,12 @@
1
-use std::io;
+use std::{io, mem::MaybeUninit};
2
3
pub fn get_current() -> Result<String, io::Error> {
4
- let uptime_seconds = unsafe {
5
- let mut info: libc::sysinfo = std::mem::zeroed();
6
- if libc::sysinfo(&mut info) != 0 {
+ let uptime_seconds = {
+ let mut info = MaybeUninit::uninit();
+ if unsafe { libc::sysinfo(info.as_mut_ptr()) } != 0 {
7
return Err(io::Error::last_os_error());
8
}
9
- info.uptime as u64
+ unsafe { info.assume_init().uptime as u64 }
10
};
11
12
let days = uptime_seconds / 86400;
0 commit comments