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
This commit is contained in:
Ryan Liptak 2022-10-14 04:39:56 -07:00
parent c5d23161fc
commit 348f73502e
2 changed files with 9 additions and 2 deletions

View File

@ -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

View File

@ -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);