From 4a71d77e66dd43bdbbc5baac1e25d8b2ed508cdd Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Thu, 26 Mar 2026 05:40:30 +0900 Subject: [PATCH] pathchk: build for Windows --- Cargo.toml | 4 ++-- src/uu/pathchk/src/pathchk.rs | 22 ++++++++++++++++++---- tests/by-util/test_pathchk.rs | 7 +++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6a816387454..57af174dc0f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -131,6 +131,7 @@ feat_common_core = [ "numfmt", "od", "paste", + "pathchk", "pr", "printenv", "printf", @@ -198,6 +199,7 @@ feat_wasm = [ "numfmt", "od", "paste", + "pathchk", "pr", "printenv", "printf", @@ -287,7 +289,6 @@ feat_require_unix_core = [ "mknod", "nice", "nohup", - "pathchk", "stat", "stty", "timeout", @@ -316,7 +317,6 @@ feat_os_unix_fuchsia = [ "mkfifo", "mknod", "nice", - "pathchk", "tty", "uname", "unlink", diff --git a/src/uu/pathchk/src/pathchk.rs b/src/uu/pathchk/src/pathchk.rs index 8ba3f4d37ac..2bf7b40a802 100644 --- a/src/uu/pathchk/src/pathchk.rs +++ b/src/uu/pathchk/src/pathchk.rs @@ -33,6 +33,20 @@ mod options { const POSIX_PATH_MAX: usize = 256; const POSIX_NAME_MAX: usize = 14; +#[cfg(all(unix, not(target_os = "redox")))] +const PATH_MAX: usize = libc::PATH_MAX as usize; +#[cfg(all(unix, not(target_os = "redox")))] +const FILENAME_MAX: usize = libc::FILENAME_MAX as usize; +#[cfg(target_os = "redox")] +const PATH_MAX: usize = 4096; +#[cfg(target_os = "redox")] +const FILENAME_MAX: usize = 255; +// for Windows. But don't deny wasm +#[cfg(not(unix))] +const PATH_MAX: usize = 260; +#[cfg(not(unix))] +const FILENAME_MAX: usize = 255; + #[uucore::main(no_signals)] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?; @@ -193,11 +207,11 @@ fn check_default(path: &[String]) -> bool { let joined_path = path.join("/"); let total_len = joined_path.len(); // path length - if total_len > libc::PATH_MAX as usize { + if total_len > PATH_MAX { writeln!( std::io::stderr(), "{}", - translate!("pathchk-error-path-length-exceeded", "limit" => libc::PATH_MAX, "length" => total_len, "path" => joined_path.quote()) + translate!("pathchk-error-path-length-exceeded", "limit" => PATH_MAX, "length" => total_len, "path" => joined_path.quote()) ); return false; } @@ -219,11 +233,11 @@ fn check_default(path: &[String]) -> bool { // components: length for p in path { let component_len = p.len(); - if component_len > libc::FILENAME_MAX as usize { + if component_len > FILENAME_MAX { writeln!( std::io::stderr(), "{}", - translate!("pathchk-error-name-length-exceeded", "limit" => libc::FILENAME_MAX, "length" => component_len, "component" => p.quote()) + translate!("pathchk-error-name-length-exceeded", "limit" => FILENAME_MAX, "length" => component_len, "component" => p.quote()) ); return false; } diff --git a/tests/by-util/test_pathchk.rs b/tests/by-util/test_pathchk.rs index 85f5c09ea0b..47fb1e01d1b 100644 --- a/tests/by-util/test_pathchk.rs +++ b/tests/by-util/test_pathchk.rs @@ -4,9 +4,11 @@ // file that was distributed with this source code. #[cfg(target_os = "linux")] use std::os::unix::ffi::OsStringExt; +#[cfg(unix)] use uutests::new_ucmd; #[test] +#[cfg(unix)] fn test_no_args() { new_ucmd!() .fails() @@ -15,11 +17,13 @@ fn test_no_args() { } #[test] +#[cfg(unix)] fn test_invalid_arg() { new_ucmd!().arg("--definitely-invalid").fails_with_code(1); } #[test] +#[cfg(unix)] fn test_default_mode() { // accept some reasonable default new_ucmd!().args(&["dir/file"]).succeeds().no_stdout(); @@ -55,6 +59,7 @@ fn test_default_mode() { } #[test] +#[cfg(unix)] fn test_posix_mode() { // accept some reasonable default new_ucmd!().args(&["-p", "dir/file"]).succeeds().no_stdout(); @@ -79,6 +84,7 @@ fn test_posix_mode() { } #[test] +#[cfg(unix)] fn test_posix_special() { // accept some reasonable default new_ucmd!().args(&["-P", "dir/file"]).succeeds().no_stdout(); @@ -118,6 +124,7 @@ fn test_posix_special() { } #[test] +#[cfg(unix)] fn test_posix_all() { // accept some reasonable default new_ucmd!()