From d4ac9f22fcd6b545a96fa72db4634bbf2418208b Mon Sep 17 00:00:00 2001 From: Knight Date: Thu, 4 Aug 2016 22:41:15 +0800 Subject: [PATCH] uptime & users: move functions extern to uucore::utmpx --- src/uptime/Cargo.toml | 2 +- src/uptime/uptime.rs | 20 +++----------------- src/users/users.rs | 19 ------------------- 3 files changed, 4 insertions(+), 37 deletions(-) diff --git a/src/uptime/Cargo.toml b/src/uptime/Cargo.toml index 977d03bf3..78fd30902 100644 --- a/src/uptime/Cargo.toml +++ b/src/uptime/Cargo.toml @@ -9,7 +9,7 @@ path = "uptime.rs" [dependencies] getopts = "*" -libc = "*" +libc = { git = "https://github.com/rust-lang/libc.git" } time = "*" uucore = { path="../uucore" } diff --git a/src/uptime/uptime.rs b/src/uptime/uptime.rs index 71e9f9cff..942fee683 100644 --- a/src/uptime/uptime.rs +++ b/src/uptime/uptime.rs @@ -19,7 +19,7 @@ extern crate time as rtime; extern crate uucore; 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::fs::File; use std::io::{Read, Write}; @@ -31,27 +31,13 @@ static NAME: &'static str = "uptime"; static VERSION: &'static str = env!("CARGO_PKG_VERSION"); #[cfg(unix)] -extern { - 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; -} +use libc::getloadavg; #[cfg(windows)] extern { 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) -> i32 { let mut opts = Options::new(); @@ -128,7 +114,7 @@ fn process_utmpx() -> (Option, usize) { BOOT_TIME => { let t = (*line).ut_tv; if t.tv_sec > 0 { - boot_time = Some(t.tv_sec); + boot_time = Some(t.tv_sec as time_t); } }, _ => continue diff --git a/src/users/users.rs b/src/users/users.rs index 86081d76a..d4394de47 100644 --- a/src/users/users.rs +++ b/src/users/users.rs @@ -26,25 +26,6 @@ use std::mem; use std::ptr; 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 VERSION: &'static str = env!("CARGO_PKG_VERSION");