From 939408289cd05ba2f3b90eb626a388b6a5c747c4 Mon Sep 17 00:00:00 2001 From: mason1920 Date: Sun, 20 Jun 2021 00:21:59 -0400 Subject: [PATCH] Bring your own MAX_PATH_BYTES Previous to #7082, users could overwrite PATH_MAX in the root file to support std.os.toPosixPath, permitting the "bring your own operating system" layer to implement the POSIX API for opening files. Unfortunately that is no longer the case. This commit intends to fix what is arguably a regression from 0.7 in a way that doesn't break any code targeting 0.8.0, making it suitable to be included in a 0.8 patch release. However in a future release that permits breaking changes, I am of the opinion that it would be beneficial to overwrite the value, even for "supported" operating systems. Same for all the other POSIX/BYOOS functions and values. However this is beyond the scope of this commit. Further discussion of this will be made into an issue in due time. --- lib/std/fs.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/std/fs.zig b/lib/std/fs.zig index a280f6ccaa..76e07b2f97 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -3,6 +3,7 @@ // This file is part of [zig](https://ziglang.org/), which is MIT licensed. // The MIT license requires this copyright notice to be included in all copies // and substantial portions of the software. +const root = @import("root"); const builtin = std.builtin; const std = @import("std.zig"); const os = std.os; @@ -47,7 +48,10 @@ pub const MAX_PATH_BYTES = switch (builtin.os.tag) { .windows => os.windows.PATH_MAX_WIDE * 3 + 1, // TODO work out what a reasonable value we should use here .wasi => 4096, - else => @compileError("Unsupported OS"), + else => if (@hasDecl(root, "os") and @hasDecl(root.os, "PATH_MAX")) + root.os.PATH_MAX + else + @compileError("PATH_MAX not implemented for " ++ @tagName(builtin.os.tag)), }; pub const base64_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".*;