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:
parent
e0c950e145
commit
6fff3a7665
3 changed files with 11 additions and 33 deletions
|
@ -17,8 +17,7 @@ use uucore::utmpx;
|
|||
|
||||
extern crate getopts;
|
||||
extern crate libc;
|
||||
use libc::{uid_t, gid_t, c_char};
|
||||
use libc::S_IWGRP;
|
||||
use libc::{uid_t, gid_t, c_char, S_IWGRP};
|
||||
|
||||
extern crate time;
|
||||
|
||||
|
@ -227,7 +226,7 @@ pub fn getpw(u: &str) -> Option<Passwd> {
|
|||
}
|
||||
}
|
||||
|
||||
trait Capitalize {
|
||||
pub trait Capitalize {
|
||||
fn capitalize(&self) -> String;
|
||||
}
|
||||
|
||||
|
@ -278,7 +277,7 @@ fn idle_string(when: i64) -> 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()
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
||||
if self.include_where && ut.ut_host[0] != 0 {
|
||||
|
|
|
@ -8,6 +8,8 @@ use self::libc::{
|
|||
uid_t,
|
||||
gid_t,
|
||||
};
|
||||
pub use self::libc::passwd as c_passwd;
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
|
||||
use self::libc::time_t;
|
||||
#[cfg(target_os = "macos")]
|
||||
|
@ -22,35 +24,6 @@ use std::vec::Vec;
|
|||
|
||||
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"))]
|
||||
#[repr(C)]
|
||||
pub struct utsname {
|
||||
|
|
|
@ -145,8 +145,11 @@ fn test_invalid_option() {
|
|||
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";
|
||||
#[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";
|
||||
#[allow(unused_variable)]
|
||||
const FS_FMTSTR: &'static str = "%a %b %c %d %f %i %l %n %s %S %t %T";
|
||||
|
||||
#[test]
|
||||
|
@ -230,6 +233,7 @@ fn test_printf() {
|
|||
assert_eq!(ucmd.run().stdout, "123?\r\"\\\x07\x08\x1B\x0C\x0B /\x12wZJ\n");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn expected_result(args: &[&str]) -> String {
|
||||
use std::process::Command;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue