diff --git a/src/stat/Cargo.toml b/src/stat/Cargo.toml index da3788528..51630441c 100644 --- a/src/stat/Cargo.toml +++ b/src/stat/Cargo.toml @@ -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" diff --git a/src/stat/fsext.rs b/src/stat/fsext.rs index a33c0adad..b7119f635 100644 --- a/src/stat/fsext.rs +++ b/src/stat/fsext.rs @@ -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; diff --git a/src/stat/stat.rs b/src/stat/stat.rs index 834396374..8450a74bc 100644 --- a/src/stat/stat.rs +++ b/src/stat/stat.rs @@ -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, 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; }