From 21cad3e09f173154c4c0dc61dd05fe8dd0628dc3 Mon Sep 17 00:00:00 2001 From: Michael Bradshaw Date: Fri, 28 Jun 2024 08:21:20 -0700 Subject: [PATCH] Rename MAX_NAME_BYTES to max_name_bytes --- lib/compiler/aro/aro/Driver.zig | 4 ++-- lib/std/fs.zig | 7 +++++-- lib/std/fs/Dir.zig | 2 +- lib/std/fs/test.zig | 4 ++-- lib/std/zig/WindowsSdk.zig | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/compiler/aro/aro/Driver.zig b/lib/compiler/aro/aro/Driver.zig index af2677626e..6876395b8a 100644 --- a/lib/compiler/aro/aro/Driver.zig +++ b/lib/compiler/aro/aro/Driver.zig @@ -730,8 +730,8 @@ fn processSource( defer obj.deinit(); // If it's used, name_buf will either hold a filename or `/tmp/<12 random bytes with base-64 encoding>.` - // both of which should fit into MAX_NAME_BYTES for all systems - var name_buf: [std.fs.MAX_NAME_BYTES]u8 = undefined; + // both of which should fit into max_name_bytes for all systems + var name_buf: [std.fs.max_name_bytes]u8 = undefined; const out_file_name = if (d.only_compile) blk: { const fmt_template = "{s}{s}"; diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 139660815a..e56d68e407 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -72,7 +72,7 @@ pub const max_path_bytes = switch (native_os) { /// On Windows, `[]u8` file name components are encoded as [WTF-8](https://simonsapin.github.io/wtf-8/). /// On WASI, file name components are encoded as valid UTF-8. /// On other platforms, `[]u8` components are an opaque sequence of bytes with no particular encoding. -pub const MAX_NAME_BYTES = switch (native_os) { +pub const max_name_bytes = switch (native_os) { .linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly, .solaris, .illumos => posix.NAME_MAX, // Haiku's NAME_MAX includes the null terminator, so subtract one. .haiku => posix.NAME_MAX - 1, @@ -81,7 +81,7 @@ pub const MAX_NAME_BYTES = switch (native_os) { // pair in the WTF-16LE, and we (over)account 3 bytes for it that way. .windows => windows.NAME_MAX * 3, // For WASI, the MAX_NAME will depend on the host OS, so it needs to be - // as large as the largest MAX_NAME_BYTES (Windows) in order to work on any host OS. + // as large as the largest max_name_bytes (Windows) in order to work on any host OS. // TODO determine if this is a reasonable approach .wasi => windows.NAME_MAX * 3, else => if (@hasDecl(root, "os") and @hasDecl(root.os, "NAME_MAX")) @@ -90,6 +90,9 @@ pub const MAX_NAME_BYTES = switch (native_os) { @compileError("NAME_MAX not implemented for " ++ @tagName(native_os)), }; +/// Deprecated: use `max_name_bytes` +pub const MAX_NAME_BYTES = max_name_bytes; + pub const base64_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".*; /// Base64 encoder, replacing the standard `+/` with `-_` so that it can be used in a file name on any filesystem. diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig index 9b8406d6b2..597c158d63 100644 --- a/lib/std/fs/Dir.zig +++ b/lib/std/fs/Dir.zig @@ -414,7 +414,7 @@ pub const Iterator = switch (native_os) { index: usize, end_index: usize, first_iter: bool, - name_data: [fs.MAX_NAME_BYTES]u8, + name_data: [fs.max_name_bytes]u8, const Self = @This(); diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index 593beea05d..f596c52322 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -1269,11 +1269,11 @@ test "max file name component lengths" { } else if (native_os == .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 - // (i.e. the minimum MAX_NAME_BYTES of all supported platforms). + // (i.e. the minimum max_name_bytes of all supported platforms). const maxed_wasi_filename = [_]u8{'1'} ** 255; try testFilenameLimits(tmp.dir, &maxed_wasi_filename); } else { - const maxed_ascii_filename = [_]u8{'1'} ** std.fs.MAX_NAME_BYTES; + const maxed_ascii_filename = [_]u8{'1'} ** std.fs.max_name_bytes; try testFilenameLimits(tmp.dir, &maxed_ascii_filename); } } diff --git a/lib/std/zig/WindowsSdk.zig b/lib/std/zig/WindowsSdk.zig index 35e812a7cf..99ad52bf1d 100644 --- a/lib/std/zig/WindowsSdk.zig +++ b/lib/std/zig/WindowsSdk.zig @@ -750,7 +750,7 @@ const MsvcLibDir = struct { var instances_dir = try findInstancesDir(allocator); defer instances_dir.close(); - var state_subpath_buf: [std.fs.MAX_NAME_BYTES + 32]u8 = undefined; + var state_subpath_buf: [std.fs.max_name_bytes + 32]u8 = undefined; var latest_version_lib_dir = std.ArrayListUnmanaged(u8){}; errdefer latest_version_lib_dir.deinit(allocator);