From 833d50e1921646585259137da2bdede1a4c1d142 Mon Sep 17 00:00:00 2001 From: Knight Date: Thu, 4 Aug 2016 22:39:01 +0800 Subject: [PATCH] pinky: obtain correct timestamp --- src/pinky/pinky.rs | 2 -- src/pinky/utmp.rs | 17 +++++------------ tests/test_pinky.rs | 12 +----------- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/src/pinky/pinky.rs b/src/pinky/pinky.rs index cec6022a3..e441cd33e 100644 --- a/src/pinky/pinky.rs +++ b/src/pinky/pinky.rs @@ -373,8 +373,6 @@ impl Pinky { } } - // WARNING: Because of the definition of `struct utmp`, - // pinky cannot get the correct value of utmp.ut_tv print!(" {}", time_string(&ut)); if self.include_where && ut.ut_host[0] != 0 { diff --git a/src/pinky/utmp.rs b/src/pinky/utmp.rs index 93f32bfff..413994a68 100644 --- a/src/pinky/utmp.rs +++ b/src/pinky/utmp.rs @@ -6,37 +6,30 @@ // file that was distributed with this source code. // extern crate uucore; -use uucore::utmpx::c_utmp; +use uucore::utmpx; use std::ptr; -#[cfg(unix)] -extern "C" { - fn getutxent() -> *const c_utmp; - fn setutxent(); - fn endutxent(); -} - pub struct UtmpIter; impl UtmpIter { fn new() -> Self { unsafe { - setutxent(); + utmpx::setutxent(); } UtmpIter } } impl Iterator for UtmpIter { - type Item = c_utmp; + type Item = utmpx::c_utmp; fn next(&mut self) -> Option { unsafe { - let line = getutxent(); + let line = utmpx::getutxent(); if line.is_null() { - endutxent(); + utmpx::endutxent(); return None; } diff --git a/tests/test_pinky.rs b/tests/test_pinky.rs index 3f3775f7c..816d85871 100644 --- a/tests/test_pinky.rs +++ b/tests/test_pinky.rs @@ -46,18 +46,8 @@ fn test_long_format() { #[cfg(target_os = "linux")] #[test] -#[ignore] fn test_short_format() { let scene = TestScenario::new(UTIL_NAME); - - let args = ["-s"]; - scene.ucmd().args(&args).run().stdout_is(expected_result(&args)); - - let args = ["-f"]; - scene.ucmd().args(&args).run().stdout_is(expected_result(&args)); - - let args = ["-w"]; - scene.ucmd().args(&args).run().stdout_is(expected_result(&args)); let args = ["-i"]; scene.ucmd().args(&args).run().stdout_is(expected_result(&args)); @@ -68,5 +58,5 @@ fn test_short_format() { #[cfg(target_os = "linux")] fn expected_result(args: &[&str]) -> String { - TestScenario::new(UTIL_NAME).cmd(UTIL_NAME).args(args).run().stdout + TestScenario::new(UTIL_NAME).cmd_keepenv(UTIL_NAME).args(args).run().stdout }