mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
uptime & users: move functions extern to uucore::utmpx
This commit is contained in:
parent
833d50e192
commit
d4ac9f22fc
3 changed files with 4 additions and 37 deletions
|
@ -9,7 +9,7 @@ path = "uptime.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
getopts = "*"
|
getopts = "*"
|
||||||
libc = "*"
|
libc = { git = "https://github.com/rust-lang/libc.git" }
|
||||||
time = "*"
|
time = "*"
|
||||||
uucore = { path="../uucore" }
|
uucore = { path="../uucore" }
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ extern crate time as rtime;
|
||||||
extern crate uucore;
|
extern crate uucore;
|
||||||
|
|
||||||
use getopts::Options;
|
use getopts::Options;
|
||||||
use libc::{time_t, c_double, c_int, c_char};
|
use libc::{time_t, c_double};
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
@ -31,27 +31,13 @@ static NAME: &'static str = "uptime";
|
||||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
extern {
|
use libc::getloadavg;
|
||||||
fn getloadavg(loadavg: *mut c_double, nelem: c_int) -> c_int;
|
|
||||||
|
|
||||||
fn getutxent() -> *const c_utmp;
|
|
||||||
fn setutxent();
|
|
||||||
fn endutxent();
|
|
||||||
|
|
||||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
|
||||||
fn utmpxname(file: *const c_char) -> c_int;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
extern {
|
extern {
|
||||||
fn GetTickCount() -> libc::uint32_t;
|
fn GetTickCount() -> libc::uint32_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "freebsd")]
|
|
||||||
unsafe extern fn utmpxname(_file: *const c_char) -> c_int {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let mut opts = Options::new();
|
let mut opts = Options::new();
|
||||||
|
|
||||||
|
@ -128,7 +114,7 @@ fn process_utmpx() -> (Option<time_t>, usize) {
|
||||||
BOOT_TIME => {
|
BOOT_TIME => {
|
||||||
let t = (*line).ut_tv;
|
let t = (*line).ut_tv;
|
||||||
if t.tv_sec > 0 {
|
if t.tv_sec > 0 {
|
||||||
boot_time = Some(t.tv_sec);
|
boot_time = Some(t.tv_sec as time_t);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => continue
|
_ => continue
|
||||||
|
|
|
@ -26,25 +26,6 @@ use std::mem;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use uucore::utmpx::*;
|
use uucore::utmpx::*;
|
||||||
|
|
||||||
extern {
|
|
||||||
fn getutxent() -> *const c_utmp;
|
|
||||||
fn getutxid(ut: *const c_utmp) -> *const c_utmp;
|
|
||||||
fn getutxline(ut: *const c_utmp) -> *const c_utmp;
|
|
||||||
|
|
||||||
fn pututxline(ut: *const c_utmp) -> *const c_utmp;
|
|
||||||
|
|
||||||
fn setutxent();
|
|
||||||
fn endutxent();
|
|
||||||
|
|
||||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
|
||||||
fn utmpxname(file: *const libc::c_char) -> libc::c_int;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "freebsd")]
|
|
||||||
unsafe extern fn utmpxname(_file: *const libc::c_char) -> libc::c_int {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
|
|
||||||
static NAME: &'static str = "users";
|
static NAME: &'static str = "users";
|
||||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue