Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc4e96ef

Browse files
committed
uptime: make it compile on Android & Redox
1 parent7d06ba6 commitc4e96ef

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
pubmod 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
ifletSome(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
fnuptime_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
fnprocess_utmpx(file:Option<&OsString>) ->(Option<time_t>,usize){
238243
letmut nusers =0;
239244
letmut 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+
pubfnget_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
pubfnget_uptime(boot_time:Option<time_t>) ->UResult<i64>{
95101
usecrate::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
pubfnget_nusers() ->usize{
198204
usecrate::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+
pubfnget_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
pubfnget_loadavg() ->UResult<(f64,f64,f64)>{
341354
usecrate::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+
pubfnget_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)

[8]ページ先頭

©2009-2025 Movatter.jp