commit 348f73502e81621b7cdb8ecf9a64bc8ebcf9db97 (tree)
parent c5d23161fcadf06089656b1f1d0fb725d7217b74
Author: Ryan Liptak <squeek502@hotmail.com>
Date: Fri, 14 Oct 2022 04:39:56 -0700
Make MAX_NAME_BYTES on WASI equivalent to the max of the other platforms
Make the test use the minimum length and set MAX_NAME_BYTES to the maximum so that:
- the test will work on any host platform
- *and* the MAX_NAME_BYTES will be able to hold the max file name component on any host platform
Diffstat:
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/lib/std/fs.zig b/lib/std/fs.zig
@@ -59,8 +59,10 @@ pub const MAX_NAME_BYTES = switch (builtin.os.tag) {
// If it would require 4 UTF-8 bytes, then there would be a surrogate
// pair in the UTF-16LE, and we (over)account 3 bytes for it that way.
.windows => os.windows.NAME_MAX * 3,
- // TODO work out what a reasonable value we should use here
- .wasi => 255,
+ // For WASI, the MAX_NAME will depend on the host OS, so it needs to be
+ // as large as the largest MAX_NAME_BYTES in order to work on any host OS.
+ // TODO determine if this is a reasonable approach
+ .wasi => os.windows.NAME_MAX * 3,
else => if (@hasDecl(root, "os") and @hasDecl(root.os, "NAME_MAX"))
root.os.NAME_MAX
else
diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig
@@ -735,6 +735,11 @@ test "filename limits" {
// so Windows allows for NAME_MAX of them
const maxed_windows_filename = ("€".*) ** std.os.windows.NAME_MAX;
try testFilenameLimits(tmp.iterable_dir, &maxed_windows_filename);
+ } else if (builtin.os.tag == .wasi) {
+ // On WASI, the maxed filename depends on the host OS, so in order for this test to
+ // work on any host, we need to use a length that will work for all platforms.
+ const maxed_wasi_filename = [_]u8{'1'} ** 255;
+ try testFilenameLimits(tmp.iterable_dir, &maxed_wasi_filename);
} else {
const maxed_ascii_filename = [_]u8{'1'} ** std.fs.MAX_NAME_BYTES;
try testFilenameLimits(tmp.iterable_dir, &maxed_ascii_filename);