Skip to content

Commit 150960a

Browse files
committed
uucore&uptime: fix docs and warnings
1 parent b1fc601 commit 150960a

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/uu/uptime/src/uptime.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ pub mod options {
3030
pub static PATH: &str = "path";
3131
}
3232

33-
#[cfg(windows)]
34-
extern "C" {
35-
fn GetTickCount() -> u32;
36-
}
37-
3833
#[derive(Debug, Error)]
3934
pub enum UptimeError {
4035
// io::Error wrapper

src/uucore/src/lib/features/uptime.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,18 @@ pub fn get_uptime(boot_time: Option<time_t>) -> UResult<i64> {
140140

141141
/// Get the system uptime
142142
///
143+
/// # Arguments
144+
///
145+
/// boot_time will be ignored, pass None.
146+
///
143147
/// # Returns
144148
///
145149
/// Returns a UResult with the uptime in seconds if successful, otherwise an UptimeError.
146150
#[cfg(windows)]
147151
pub fn get_uptime(_boot_time: Option<time_t>) -> UResult<i64> {
148152
use windows_sys::Win32::System::SystemInformation::GetTickCount;
153+
// SAFETY: always return u32
149154
let uptime = unsafe { GetTickCount() };
150-
if uptime < 0 {
151-
Err(UptimeError::SystemUptime)?;
152-
}
153155
Ok(uptime as i64 / 1000)
154156
}
155157

@@ -244,6 +246,7 @@ pub fn get_nusers() -> usize {
244246

245247
let mut num_user = 0;
246248

249+
// SAFETY: WTS_CURRENT_SERVER_HANDLE is a valid handle
247250
unsafe {
248251
let mut session_info_ptr = ptr::null_mut();
249252
let mut session_count = 0;
@@ -335,6 +338,7 @@ pub fn get_loadavg() -> UResult<(f64, f64, f64)> {
335338
use libc::getloadavg;
336339

337340
let mut avg: [c_double; 3] = [0.0; 3];
341+
// SAFETY: checked whether it returns -1
338342
let loads: i32 = unsafe { getloadavg(avg.as_mut_ptr(), 3) };
339343

340344
if loads == -1 {

0 commit comments

Comments
 (0)