mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 13:37:48 +00:00
stat: use uucore::entries
This commit is contained in:
parent
40e6c5a397
commit
99f0114450
3 changed files with 14 additions and 35 deletions
|
@ -9,9 +9,12 @@ path = "stat.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "*"
|
||||
libc = "^0.2"
|
||||
time = "*"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
features = ["entries"]
|
||||
|
||||
[[bin]]
|
||||
name = "stat"
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
// that was distributed with this source code.
|
||||
//
|
||||
|
||||
extern crate libc;
|
||||
pub use super::uucore::libc;
|
||||
extern crate time;
|
||||
|
||||
use self::time::Timespec;
|
||||
pub use self::libc::{S_IFMT, S_IFDIR, S_IFCHR, S_IFBLK, S_IFREG, S_IFIFO, S_IFLNK, S_IFSOCK, S_ISUID, S_ISGID,
|
||||
S_ISVTX, S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IWGRP, S_IXGRP, S_IROTH, S_IWOTH, S_IXOTH, mode_t,
|
||||
c_int, strerror};
|
||||
pub use libc::{S_IFMT, S_IFDIR, S_IFCHR, S_IFBLK, S_IFREG, S_IFIFO, S_IFLNK, S_IFSOCK, S_ISUID, S_ISGID, S_ISVTX,
|
||||
S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IWGRP, S_IXGRP, S_IROTH, S_IWOTH, S_IXOTH, mode_t, c_int,
|
||||
strerror};
|
||||
|
||||
pub trait BirthTime {
|
||||
fn pretty_birth(&self) -> String;
|
||||
|
@ -176,12 +176,12 @@ use std::error::Error;
|
|||
use std::io::Error as IOError;
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "android"))]
|
||||
use self::libc::statfs as Sstatfs;
|
||||
use libc::statfs as Sstatfs;
|
||||
// #[cfg(any(target_os = "openbsd", target_os = "netbsd", target_os = "openbsd", target_os = "bitrig", target_os = "dragonfly"))]
|
||||
// use self::libc::statvfs as Sstatfs;
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "android"))]
|
||||
use self::libc::statfs as statfs_fn;
|
||||
use libc::statfs as statfs_fn;
|
||||
// #[cfg(any(target_os = "openbsd", target_os = "netbsd", target_os = "openbsd", target_os = "bitrig", target_os = "dragonfly"))]
|
||||
// use self::libc::statvfs as statfs_fn;
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ pub use fsext::*;
|
|||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
use uucore::entries;
|
||||
|
||||
use std::{fs, iter, cmp};
|
||||
use std::fs::File;
|
||||
|
@ -319,31 +320,6 @@ fn print_it(arg: &str, otype: OutputType, flag: u8, width: usize, precision: i32
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
use std::ptr;
|
||||
use std::ffi::CStr;
|
||||
use uucore::c_types::{getpwuid, getgrgid};
|
||||
fn get_grp_name(gid: u32) -> String {
|
||||
let p = unsafe { getgrgid(gid) };
|
||||
if !p.is_null() {
|
||||
unsafe { CStr::from_ptr(ptr::read(p).gr_name).to_string_lossy().into_owned() }
|
||||
} else {
|
||||
"UNKNOWN".to_owned()
|
||||
}
|
||||
}
|
||||
fn get_usr_name(uid: u32) -> String {
|
||||
let p = unsafe { getpwuid(uid) };
|
||||
if !p.is_null() {
|
||||
unsafe {
|
||||
CStr::from_ptr(ptr::read(p).pw_name)
|
||||
.to_string_lossy()
|
||||
.into_owned()
|
||||
}
|
||||
} else {
|
||||
"UNKNOWN".to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
impl Stater {
|
||||
pub fn generate_tokens(fmtstr: &str, use_printf: bool) -> Result<Vec<Token>, String> {
|
||||
|
||||
|
@ -613,7 +589,7 @@ impl Stater {
|
|||
}
|
||||
// group name of owner
|
||||
'G' => {
|
||||
arg = get_grp_name(meta.gid());
|
||||
arg = entries::gid2grp(meta.gid()).unwrap_or("UNKNOWN".to_owned());
|
||||
otype = OutputType::Str;
|
||||
}
|
||||
// number of hard links
|
||||
|
@ -683,7 +659,7 @@ impl Stater {
|
|||
}
|
||||
// user name of owner
|
||||
'U' => {
|
||||
arg = get_usr_name(meta.uid());
|
||||
arg = entries::uid2usr(meta.uid()).unwrap_or("UNKNOWN".to_owned());
|
||||
otype = OutputType::Str;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue