1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

pinky: obtain correct timestamp

This commit is contained in:
Knight 2016-08-04 22:39:01 +08:00
parent 0020d5c80c
commit 833d50e192
3 changed files with 6 additions and 25 deletions

View file

@ -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)); print!(" {}", time_string(&ut));
if self.include_where && ut.ut_host[0] != 0 { if self.include_where && ut.ut_host[0] != 0 {

View file

@ -6,37 +6,30 @@
// file that was distributed with this source code. // file that was distributed with this source code.
// //
extern crate uucore; extern crate uucore;
use uucore::utmpx::c_utmp; use uucore::utmpx;
use std::ptr; use std::ptr;
#[cfg(unix)]
extern "C" {
fn getutxent() -> *const c_utmp;
fn setutxent();
fn endutxent();
}
pub struct UtmpIter; pub struct UtmpIter;
impl UtmpIter { impl UtmpIter {
fn new() -> Self { fn new() -> Self {
unsafe { unsafe {
setutxent(); utmpx::setutxent();
} }
UtmpIter UtmpIter
} }
} }
impl Iterator for UtmpIter { impl Iterator for UtmpIter {
type Item = c_utmp; type Item = utmpx::c_utmp;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
unsafe { unsafe {
let line = getutxent(); let line = utmpx::getutxent();
if line.is_null() { if line.is_null() {
endutxent(); utmpx::endutxent();
return None; return None;
} }

View file

@ -46,19 +46,9 @@ fn test_long_format() {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
#[test] #[test]
#[ignore]
fn test_short_format() { fn test_short_format() {
let scene = TestScenario::new(UTIL_NAME); 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"]; let args = ["-i"];
scene.ucmd().args(&args).run().stdout_is(expected_result(&args)); scene.ucmd().args(&args).run().stdout_is(expected_result(&args));
@ -68,5 +58,5 @@ fn test_short_format() {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn expected_result(args: &[&str]) -> String { 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
} }