pathchk: build for Windows

This commit is contained in:
oech3
2026-03-26 05:40:30 +09:00
committed by Daniel Hofstetter
parent c7710ac0b7
commit aab0ddac47
3 changed files with 27 additions and 6 deletions
+2 -2
View File
@@ -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",
+18 -4
View File
@@ -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;
}
+7
View File
@@ -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!()