authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2022-10-14 04:39:56-07:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2022-10-29 14:30:46-07:00
log348f73502e81621b7cdb8ecf9a64bc8ebcf9db97
tree265dd884304d939de36e65a4591cd6d5b3a53e91
parentc5d23161fcadf06089656b1f1d0fb725d7217b74

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

2 files changed, 9 insertions(+), 2 deletions(-)

lib/std/fs.zig+4-2
...@@ -59,8 +59,10 @@ pub const MAX_NAME_BYTES = switch (builtin.os.tag) {...@@ -59,8 +59,10 @@ pub const MAX_NAME_BYTES = switch (builtin.os.tag) {
59 // If it would require 4 UTF-8 bytes, then there would be a surrogate59 // If it would require 4 UTF-8 bytes, then there would be a surrogate
60 // pair in the UTF-16LE, and we (over)account 3 bytes for it that way.60 // pair in the UTF-16LE, and we (over)account 3 bytes for it that way.
61 .windows => os.windows.NAME_MAX * 3,61 .windows => os.windows.NAME_MAX * 3,
62 // TODO work out what a reasonable value we should use here62 // For WASI, the MAX_NAME will depend on the host OS, so it needs to be
63 .wasi => 255,63 // as large as the largest MAX_NAME_BYTES in order to work on any host OS.
64 // TODO determine if this is a reasonable approach
65 .wasi => os.windows.NAME_MAX * 3,
64 else => if (@hasDecl(root, "os") and @hasDecl(root.os, "NAME_MAX"))66 else => if (@hasDecl(root, "os") and @hasDecl(root.os, "NAME_MAX"))
65 root.os.NAME_MAX67 root.os.NAME_MAX
66 else68 else
lib/std/fs/test.zig+5
...@@ -735,6 +735,11 @@ test "filename limits" {...@@ -735,6 +735,11 @@ test "filename limits" {
735 // so Windows allows for NAME_MAX of them735 // so Windows allows for NAME_MAX of them
736 const maxed_windows_filename = ("€".*) ** std.os.windows.NAME_MAX;736 const maxed_windows_filename = ("€".*) ** std.os.windows.NAME_MAX;
737 try testFilenameLimits(tmp.iterable_dir, &maxed_windows_filename);737 try testFilenameLimits(tmp.iterable_dir, &maxed_windows_filename);
738 } else if (builtin.os.tag == .wasi) {
739 // On WASI, the maxed filename depends on the host OS, so in order for this test to
740 // work on any host, we need to use a length that will work for all platforms.
741 const maxed_wasi_filename = [_]u8{'1'} ** 255;
742 try testFilenameLimits(tmp.iterable_dir, &maxed_wasi_filename);
738 } else {743 } else {
739 const maxed_ascii_filename = [_]u8{'1'} ** std.fs.MAX_NAME_BYTES;744 const maxed_ascii_filename = [_]u8{'1'} ** std.fs.MAX_NAME_BYTES;
740 try testFilenameLimits(tmp.iterable_dir, &maxed_ascii_filename);745 try testFilenameLimits(tmp.iterable_dir, &maxed_ascii_filename);