Skip to content

Commit c4e96ef

Browse files
committed
uptime: make it compile on Android & Redox
1 parent 7d06ba6 commit c4e96ef

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

src/uu/uptime/src/uptime.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use uucore::format_usage;
2020

2121
use uucore::locale::{get_message, get_message_with_args};
2222
#[cfg(unix)]
23-
#[cfg(not(target_os = "openbsd"))]
23+
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "android")))]
2424
use uucore::utmpx::*;
2525

2626
pub mod options {
@@ -162,7 +162,7 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
162162
print_time();
163163
let user_count;
164164

165-
#[cfg(not(target_os = "openbsd"))]
165+
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "android")))]
166166
{
167167
let (boot_time, count) = process_utmpx(Some(file_path));
168168
if let Some(time) = boot_time {
@@ -176,7 +176,7 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
176176
user_count = count;
177177
}
178178

179-
#[cfg(target_os = "openbsd")]
179+
#[cfg(any(target_os = "openbsd", target_os = "redox", target_os = "android"))]
180180
{
181181
let upsecs = get_uptime(None);
182182
if upsecs >= 0 {
@@ -198,12 +198,17 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
198198

199199
fn uptime_since() -> UResult<()> {
200200
#[cfg(unix)]
201-
#[cfg(not(target_os = "openbsd"))]
201+
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "android")))]
202202
let uptime = {
203203
let (boot_time, _) = process_utmpx(None);
204204
get_uptime(boot_time)?
205205
};
206-
#[cfg(any(windows, target_os = "openbsd"))]
206+
#[cfg(any(
207+
windows,
208+
target_os = "openbsd",
209+
target_os = "redox",
210+
target_os = "android"
211+
))]
207212
let uptime = get_uptime(None)?;
208213

209214
let since_date = Local
@@ -233,7 +238,7 @@ fn print_loadavg() {
233238
}
234239

235240
#[cfg(unix)]
236-
#[cfg(not(target_os = "openbsd"))]
241+
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "android")))]
237242
fn process_utmpx(file: Option<&OsString>) -> (Option<time_t>, usize) {
238243
let mut nusers = 0;
239244
let mut boot_time = None;

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ pub fn get_uptime(_boot_time: Option<time_t>) -> UResult<i64> {
8080
}
8181
}
8282

83+
// TODO implement functionality
84+
#[cfg(any(target_os = "android", target_os = "redox"))]
85+
pub fn get_uptime(_boot_time: Option<time_t>) -> UResult<i64> {
86+
Err(UptimeError::SystemUptime)?
87+
}
88+
8389
/// Get the system uptime
8490
///
8591
/// # Arguments
@@ -90,7 +96,7 @@ pub fn get_uptime(_boot_time: Option<time_t>) -> UResult<i64> {
9096
///
9197
/// Returns a UResult with the uptime in seconds if successful, otherwise an UptimeError.
9298
#[cfg(unix)]
93-
#[cfg(not(target_os = "openbsd"))]
99+
#[cfg(not(any(target_os = "openbsd", target_os = "android", target_os = "redox")))]
94100
pub fn get_uptime(boot_time: Option<time_t>) -> UResult<i64> {
95101
use crate::utmpx::Utmpx;
96102
use libc::BOOT_TIME;
@@ -192,7 +198,7 @@ pub fn get_formatted_uptime(boot_time: Option<time_t>) -> UResult<String> {
192198
///
193199
/// Returns the number of users currently logged in if successful, otherwise 0.
194200
#[cfg(unix)]
195-
#[cfg(not(target_os = "openbsd"))]
201+
#[cfg(not(any(target_os = "openbsd", target_os = "android", target_os = "redox")))]
196202
// see: https://gitlab.com/procps-ng/procps/-/blob/4740a0efa79cade867cfc7b32955fe0f75bf5173/library/uptime.c#L63-L115
197203
pub fn get_nusers() -> usize {
198204
use crate::utmpx::Utmpx;
@@ -239,6 +245,12 @@ pub fn get_nusers(file: &str) -> usize {
239245
nusers
240246
}
241247

248+
// TODO implement functionality
249+
#[cfg(any(target_os = "android", target_os = "redox"))]
250+
pub fn get_nusers() -> usize {
251+
0
252+
}
253+
242254
/// Get the number of users currently logged in
243255
///
244256
/// # Returns
@@ -337,6 +349,7 @@ pub fn get_formatted_nusers() -> String {
337349
/// Returns a UResult with the load average if successful, otherwise an UptimeError.
338350
/// The load average is a tuple of three floating point numbers representing the 1-minute, 5-minute, and 15-minute load averages.
339351
#[cfg(unix)]
352+
#[cfg(not(any(target_os = "android", target_os = "redox")))]
340353
pub fn get_loadavg() -> UResult<(f64, f64, f64)> {
341354
use crate::libc::c_double;
342355
use libc::getloadavg;
@@ -352,6 +365,12 @@ pub fn get_loadavg() -> UResult<(f64, f64, f64)> {
352365
}
353366
}
354367

368+
// TODO implement functionality
369+
#[cfg(any(target_os = "android", target_os = "redox"))]
370+
pub fn get_loadavg() -> UResult<(f64, f64, f64)> {
371+
Err(UptimeError::SystemLoadavg)?
372+
}
373+
355374
/// Get the system load average
356375
/// Windows does not have an equivalent to the load average on Unix-like systems.
357376
///

0 commit comments

Comments
 (0)