Skip to content

Commit

Permalink
try to fix windows
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Jan 24, 2025
1 parent b8b1671 commit 2aa6434
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/uu/printf/src/printf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,21 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let format = format.as_bytes();

#[cfg(windows)]
let format_vec: Vec<u8> = 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::<std::ffi::OsString>(options::ARGUMENT) {
Some(s) => s
.map(|os_str| {
#[cfg(unix)]
let raw_bytes: Vec<u8> = 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<u8> = 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![],
Expand Down

0 comments on commit 2aa6434

Please sign in to comment.