1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

uucore&uptime: fix docs and warnings

This commit is contained in:
Bluemangoo 2025-03-10 18:12:00 +08:00
parent b1fc601cf8
commit 150960ac5c
No known key found for this signature in database
GPG key ID: F2F7E46880A1C4CF
2 changed files with 7 additions and 8 deletions

View file

@ -30,11 +30,6 @@ pub mod options {
pub static PATH: &str = "path"; pub static PATH: &str = "path";
} }
#[cfg(windows)]
extern "C" {
fn GetTickCount() -> u32;
}
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum UptimeError { pub enum UptimeError {
// io::Error wrapper // io::Error wrapper

View file

@ -140,16 +140,18 @@ pub fn get_uptime(boot_time: Option<time_t>) -> UResult<i64> {
/// Get the system uptime /// Get the system uptime
/// ///
/// # Arguments
///
/// boot_time will be ignored, pass None.
///
/// # Returns /// # Returns
/// ///
/// Returns a UResult with the uptime in seconds if successful, otherwise an UptimeError. /// Returns a UResult with the uptime in seconds if successful, otherwise an UptimeError.
#[cfg(windows)] #[cfg(windows)]
pub fn get_uptime(_boot_time: Option<time_t>) -> UResult<i64> { pub fn get_uptime(_boot_time: Option<time_t>) -> UResult<i64> {
use windows_sys::Win32::System::SystemInformation::GetTickCount; use windows_sys::Win32::System::SystemInformation::GetTickCount;
// SAFETY: always return u32
let uptime = unsafe { GetTickCount() }; let uptime = unsafe { GetTickCount() };
if uptime < 0 {
Err(UptimeError::SystemUptime)?;
}
Ok(uptime as i64 / 1000) Ok(uptime as i64 / 1000)
} }
@ -244,6 +246,7 @@ pub fn get_nusers() -> usize {
let mut num_user = 0; let mut num_user = 0;
// SAFETY: WTS_CURRENT_SERVER_HANDLE is a valid handle
unsafe { unsafe {
let mut session_info_ptr = ptr::null_mut(); let mut session_info_ptr = ptr::null_mut();
let mut session_count = 0; let mut session_count = 0;
@ -335,6 +338,7 @@ pub fn get_loadavg() -> UResult<(f64, f64, f64)> {
use libc::getloadavg; use libc::getloadavg;
let mut avg: [c_double; 3] = [0.0; 3]; let mut avg: [c_double; 3] = [0.0; 3];
// SAFETY: checked whether it returns -1
let loads: i32 = unsafe { getloadavg(avg.as_mut_ptr(), 3) }; let loads: i32 = unsafe { getloadavg(avg.as_mut_ptr(), 3) };
if loads == -1 { if loads == -1 {