Commit 348f73502e
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);
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