Skip to content

Commit aab0dda

Browse files
oech3cakebaker
authored andcommitted
pathchk: build for Windows
1 parent c7710ac commit aab0dda

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ feat_common_core = [
131131
"numfmt",
132132
"od",
133133
"paste",
134+
"pathchk",
134135
"pr",
135136
"printenv",
136137
"printf",
@@ -198,6 +199,7 @@ feat_wasm = [
198199
"numfmt",
199200
"od",
200201
"paste",
202+
"pathchk",
201203
"pr",
202204
"printenv",
203205
"printf",
@@ -287,7 +289,6 @@ feat_require_unix_core = [
287289
"mknod",
288290
"nice",
289291
"nohup",
290-
"pathchk",
291292
"stat",
292293
"stty",
293294
"timeout",
@@ -316,7 +317,6 @@ feat_os_unix_fuchsia = [
316317
"mkfifo",
317318
"mknod",
318319
"nice",
319-
"pathchk",
320320
"tty",
321321
"uname",
322322
"unlink",

src/uu/pathchk/src/pathchk.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ mod options {
3333
const POSIX_PATH_MAX: usize = 256;
3434
const POSIX_NAME_MAX: usize = 14;
3535

36+
#[cfg(all(unix, not(target_os = "redox")))]
37+
const PATH_MAX: usize = libc::PATH_MAX as usize;
38+
#[cfg(all(unix, not(target_os = "redox")))]
39+
const FILENAME_MAX: usize = libc::FILENAME_MAX as usize;
40+
#[cfg(target_os = "redox")]
41+
const PATH_MAX: usize = 4096;
42+
#[cfg(target_os = "redox")]
43+
const FILENAME_MAX: usize = 255;
44+
// for Windows. But don't deny wasm
45+
#[cfg(not(unix))]
46+
const PATH_MAX: usize = 260;
47+
#[cfg(not(unix))]
48+
const FILENAME_MAX: usize = 255;
49+
3650
#[uucore::main(no_signals)]
3751
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
3852
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
@@ -193,11 +207,11 @@ fn check_default(path: &[String]) -> bool {
193207
let joined_path = path.join("/");
194208
let total_len = joined_path.len();
195209
// path length
196-
if total_len > libc::PATH_MAX as usize {
210+
if total_len > PATH_MAX {
197211
writeln!(
198212
std::io::stderr(),
199213
"{}",
200-
translate!("pathchk-error-path-length-exceeded", "limit" => libc::PATH_MAX, "length" => total_len, "path" => joined_path.quote())
214+
translate!("pathchk-error-path-length-exceeded", "limit" => PATH_MAX, "length" => total_len, "path" => joined_path.quote())
201215
);
202216
return false;
203217
}
@@ -219,11 +233,11 @@ fn check_default(path: &[String]) -> bool {
219233
// components: length
220234
for p in path {
221235
let component_len = p.len();
222-
if component_len > libc::FILENAME_MAX as usize {
236+
if component_len > FILENAME_MAX {
223237
writeln!(
224238
std::io::stderr(),
225239
"{}",
226-
translate!("pathchk-error-name-length-exceeded", "limit" => libc::FILENAME_MAX, "length" => component_len, "component" => p.quote())
240+
translate!("pathchk-error-name-length-exceeded", "limit" => FILENAME_MAX, "length" => component_len, "component" => p.quote())
227241
);
228242
return false;
229243
}

tests/by-util/test_pathchk.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
// file that was distributed with this source code.
55
#[cfg(target_os = "linux")]
66
use std::os::unix::ffi::OsStringExt;
7+
#[cfg(unix)]
78
use uutests::new_ucmd;
89

910
#[test]
11+
#[cfg(unix)]
1012
fn test_no_args() {
1113
new_ucmd!()
1214
.fails()
@@ -15,11 +17,13 @@ fn test_no_args() {
1517
}
1618

1719
#[test]
20+
#[cfg(unix)]
1821
fn test_invalid_arg() {
1922
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
2023
}
2124

2225
#[test]
26+
#[cfg(unix)]
2327
fn test_default_mode() {
2428
// accept some reasonable default
2529
new_ucmd!().args(&["dir/file"]).succeeds().no_stdout();
@@ -55,6 +59,7 @@ fn test_default_mode() {
5559
}
5660

5761
#[test]
62+
#[cfg(unix)]
5863
fn test_posix_mode() {
5964
// accept some reasonable default
6065
new_ucmd!().args(&["-p", "dir/file"]).succeeds().no_stdout();
@@ -79,6 +84,7 @@ fn test_posix_mode() {
7984
}
8085

8186
#[test]
87+
#[cfg(unix)]
8288
fn test_posix_special() {
8389
// accept some reasonable default
8490
new_ucmd!().args(&["-P", "dir/file"]).succeeds().no_stdout();
@@ -118,6 +124,7 @@ fn test_posix_special() {
118124
}
119125

120126
#[test]
127+
#[cfg(unix)]
121128
fn test_posix_all() {
122129
// accept some reasonable default
123130
new_ucmd!()

0 commit comments

Comments
 (0)