1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

pinky: cleanup the code

This commit is contained in:
Knight 2016-07-26 16:43:03 +08:00
parent e0c950e145
commit 6fff3a7665
3 changed files with 11 additions and 33 deletions

View file

@ -17,8 +17,7 @@ use uucore::utmpx;
extern crate getopts; extern crate getopts;
extern crate libc; extern crate libc;
use libc::{uid_t, gid_t, c_char}; use libc::{uid_t, gid_t, c_char, S_IWGRP};
use libc::S_IWGRP;
extern crate time; extern crate time;
@ -227,7 +226,7 @@ pub fn getpw(u: &str) -> Option<Passwd> {
} }
} }
trait Capitalize { pub trait Capitalize {
fn capitalize(&self) -> String; fn capitalize(&self) -> String;
} }
@ -278,7 +277,7 @@ fn idle_string(when: i64) -> String {
} }
fn time_string(ut: &utmpx::c_utmp) -> String { fn time_string(ut: &utmpx::c_utmp) -> String {
let tm = time::at(time::Timespec::new(ut.ut_tv.tv_sec, ut.ut_tv.tv_usec as i32)); let tm = time::at(time::Timespec::new(ut.ut_tv.tv_sec as i64, ut.ut_tv.tv_usec as i32));
time::strftime("%Y-%m-%d %H:%M", &tm).unwrap() time::strftime("%Y-%m-%d %H:%M", &tm).unwrap()
} }
@ -374,6 +373,8 @@ 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

@ -8,6 +8,8 @@ use self::libc::{
uid_t, uid_t,
gid_t, gid_t,
}; };
pub use self::libc::passwd as c_passwd;
#[cfg(any(target_os = "macos", target_os = "freebsd"))] #[cfg(any(target_os = "macos", target_os = "freebsd"))]
use self::libc::time_t; use self::libc::time_t;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
@ -22,35 +24,6 @@ use std::vec::Vec;
use std::ptr::{null_mut, read}; use std::ptr::{null_mut, read};
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
#[repr(C)]
#[derive(Clone, Copy)]
pub struct c_passwd {
pub pw_name: *const c_char, /* user name */
pub pw_passwd: *const c_char, /* user name */
pub pw_uid: uid_t, /* user uid */
pub pw_gid: gid_t, /* user gid */
pub pw_change: time_t,
pub pw_class: *const c_char,
pub pw_gecos: *const c_char,
pub pw_dir: *const c_char,
pub pw_shell: *const c_char,
pub pw_expire: time_t
}
#[cfg(target_os = "linux")]
#[repr(C)]
#[derive(Clone, Copy)]
pub struct c_passwd {
pub pw_name: *const c_char, /* user name */
pub pw_passwd: *const c_char, /* user name */
pub pw_uid: uid_t, /* user uid */
pub pw_gid: gid_t, /* user gid */
pub pw_gecos: *const c_char,
pub pw_dir: *const c_char,
pub pw_shell: *const c_char,
}
#[cfg(any(target_os = "macos", target_os = "freebsd"))] #[cfg(any(target_os = "macos", target_os = "freebsd"))]
#[repr(C)] #[repr(C)]
pub struct utsname { pub struct utsname {

View file

@ -145,8 +145,11 @@ fn test_invalid_option() {
ucmd.fails(); ucmd.fails();
} }
#[allow(unused_variable)]
const NORMAL_FMTSTR: &'static str = "%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s %u %U %w %W %x %X %y %Y %z %Z"; const NORMAL_FMTSTR: &'static str = "%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s %u %U %w %W %x %X %y %Y %z %Z";
#[allow(unused_variable)]
const DEV_FMTSTR: &'static str = "%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s (%t/%T) %u %U %w %W %x %X %y %Y %z %Z"; const DEV_FMTSTR: &'static str = "%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s (%t/%T) %u %U %w %W %x %X %y %Y %z %Z";
#[allow(unused_variable)]
const FS_FMTSTR: &'static str = "%a %b %c %d %f %i %l %n %s %S %t %T"; const FS_FMTSTR: &'static str = "%a %b %c %d %f %i %l %n %s %S %t %T";
#[test] #[test]
@ -230,6 +233,7 @@ fn test_printf() {
assert_eq!(ucmd.run().stdout, "123?\r\"\\\x07\x08\x1B\x0C\x0B /\x12wZJ\n"); assert_eq!(ucmd.run().stdout, "123?\r\"\\\x07\x08\x1B\x0C\x0B /\x12wZJ\n");
} }
#[allow(dead_code)]
fn expected_result(args: &[&str]) -> String { fn expected_result(args: &[&str]) -> String {
use std::process::Command; use std::process::Command;