From 71a6ae14434ac358da3384a32f08e842f5eba803 Mon Sep 17 00:00:00 2001 From: Kartik Sharma Date: Sun, 20 Mar 2022 17:57:00 +0530 Subject: [PATCH] Added support to read a filename redirected to stdin - Canonicalization of `/dev/stdin` which points to stdin file --- src/uu/stat/src/stat.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index 569c94d96..512eb6a8a 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -471,11 +471,18 @@ impl Stater { } fn new(matches: &ArgMatches) -> UResult { - let files: Vec = matches + let mut files: Vec = matches .values_of(ARG_FILES) .map(|v| v.map(ToString::to_string).collect()) .unwrap_or_default(); - + #[cfg(unix)] + if files.contains(&String::from("-")) { + files = Vec::from([Path::new("/dev/stdin") + .canonicalize()? + .into_os_string() + .into_string() + .unwrap()]); + } let format_str = if matches.is_present(options::PRINTF) { matches .value_of(options::PRINTF)