Skip to content

Commit a340afb

Browse files
pocopepeviju
andauthored
fix build failure on wasm32-wasip1 target (#215)
Co-authored-by: viju <pocopepe@vijus-MacBook-Air.local>
1 parent 18c5533 commit a340afb

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/cmp.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use std::iter::Peekable;
1111
use std::process::ExitCode;
1212
use std::{cmp, fs, io};
1313

14-
#[cfg(not(target_os = "windows"))]
14+
#[cfg(unix)]
1515
use std::os::fd::{AsRawFd, FromRawFd};
1616

17-
#[cfg(not(target_os = "windows"))]
17+
#[cfg(unix)]
1818
use std::os::unix::fs::MetadataExt;
1919

2020
#[cfg(target_os = "windows")]
@@ -38,7 +38,7 @@ fn usage_string(executable: &str) -> String {
3838
format!("Usage: {executable} <from> <to>")
3939
}
4040

41-
#[cfg(not(target_os = "windows"))]
41+
#[cfg(unix)]
4242
fn is_stdout_dev_null() -> bool {
4343
let Ok(dev_null) = fs::metadata("/dev/null") else {
4444
return false;
@@ -60,6 +60,11 @@ fn is_stdout_dev_null() -> bool {
6060
is_dev_null
6161
}
6262

63+
#[cfg(not(any(unix, target_os = "windows")))]
64+
fn is_stdout_dev_null() -> bool {
65+
false
66+
}
67+
6368
pub fn parse_params<I: Iterator<Item = OsString>>(mut opts: Peekable<I>) -> Result<Params, String> {
6469
let Some(executable) = opts.next() else {
6570
return Err("Usage: <exe> <from> <to>".to_string());
@@ -330,7 +335,7 @@ pub fn cmp(params: &Params) -> Result<Cmp, String> {
330335

331336
if let (Ok(a_meta), Ok(b_meta)) = (fs::metadata(&params.from), fs::metadata(&params.to)) {
332337
#[cfg(not(target_os = "windows"))]
333-
let (a_size, b_size) = (a_meta.size(), b_meta.size());
338+
let (a_size, b_size) = (a_meta.len(), b_meta.len());
334339

335340
#[cfg(target_os = "windows")]
336341
let (a_size, b_size) = (a_meta.file_size(), b_meta.file_size());

0 commit comments

Comments
 (0)