diff --git a/src/uu/printf/src/printf.rs b/src/uu/printf/src/printf.rs index e9f38d38b12..db25d635ebe 100644 --- a/src/uu/printf/src/printf.rs +++ b/src/uu/printf/src/printf.rs @@ -36,28 +36,21 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let format = format.as_bytes(); #[cfg(windows)] - let format_vec: Vec = format - .encode_wide() - .flat_map(|wchar| wchar.to_le_bytes()) - .collect(); - #[cfg(windows)] - let format = format_vec.as_slice(); + let format = as_os_str().as_bytes_lossy(); let values: Vec<_> = match matches.get_many::(options::ARGUMENT) { Some(s) => s .map(|os_str| { - #[cfg(unix)] let raw_bytes: Vec = os_str.clone().into_vec(); - + #[cfg(unix)] + { + FormatArgument::Unparsed( + String::from_utf8(raw_bytes.clone()) + .unwrap_or_else(|_| raw_bytes.iter().map(|&b| b as char).collect()), + ) + } #[cfg(windows)] - let raw_bytes: Vec = os_str - .encode_wide() - .flat_map(|wchar| wchar.to_le_bytes()) - .collect(); - FormatArgument::Unparsed( - String::from_utf8(raw_bytes.clone()) - .unwrap_or_else(|_| raw_bytes.iter().map(|&b| b as char).collect()), - ) + FormatArgument::Unparsed(String::from_utf8_lossy(&raw_bytes).into_owned()) }) .collect(), None => vec![],