authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2022-10-13 22:18:35-07:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2022-10-29 14:30:43-07:00
log33fdc43714e34f5c4bc02c416ef4c6534acc56ca
tree9bf688f5a789727ddc8c29ec6280e0fd3f5abe96
parente036cc48d59e5f7c025df7bbd9923a13e30c6ec9

std.fs: Add MAX_NAME_BYTES

Also add some NAME_MAX or equivalent definitions where necessary

5 files changed, 27 insertions(+), 0 deletions(-)

lib/std/c/darwin.zig+1
......@@ -1014,6 +1014,7 @@ pub const vm_machine_attribute_val_t = isize;
10141014pub const CALENDAR_CLOCK = 1;
10151015
10161016pub const PATH_MAX = 1024;
1017pub const NAME_MAX = 255;
10171018pub const IOV_MAX = 16;
10181019
10191020pub const STDIN_FILENO = 0;
lib/std/c/dragonfly.zig+1
......@@ -234,6 +234,7 @@ pub const SA = struct {
234234};
235235
236236pub const PATH_MAX = 1024;
237pub const NAME_MAX = 255;
237238pub const IOV_MAX = KERN.IOV_MAX;
238239
239240pub const ino_t = c_ulong;
lib/std/c/haiku.zig+2
......@@ -266,6 +266,7 @@ pub const area_info = extern struct {
266266};
267267
268268pub const MAXPATHLEN = PATH_MAX;
269pub const MAXNAMLEN = NAME_MAX;
269270
270271pub const image_info = extern struct {
271272 id: u32,
......@@ -371,6 +372,7 @@ pub const KERN = struct {};
371372pub const IOV_MAX = 1024;
372373
373374pub const PATH_MAX = 1024;
375pub const NAME_MAX = 256;
374376
375377pub const STDIN_FILENO = 0;
376378pub const STDOUT_FILENO = 1;
lib/std/fs.zig+17
......@@ -48,6 +48,23 @@ pub const MAX_PATH_BYTES = switch (builtin.os.tag) {
4848 @compileError("PATH_MAX not implemented for " ++ @tagName(builtin.os.tag)),
4949};
5050
51/// This represents the maximum size of a UTF-8 encoded file name component that the
52/// operating system will accept. All file name components returned by file system
53/// operations are assumed to fit into a UTF-8 encoded array of this length.
54/// The byte count does not include a null sentinel byte.
55pub const MAX_NAME_BYTES = switch (builtin.os.tag) {
56 .linux, .macos, .ios, .freebsd, .dragonfly, .haiku => os.NAME_MAX,
57 .netbsd, .openbsd, .solaris => os.MAXNAMLEN,
58 // Each UTF-16LE character may be expanded to 3 UTF-8 bytes.
59 // 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.
61 .windows => os.NAME_MAX * 3,
62 else => if (@hasDecl(root, "os") and @hasDecl(root.os, "NAME_MAX"))
63 root.os.NAME_MAX
64 else
65 @compileError("NAME_MAX not implemented for " ++ @tagName(builtin.os.tag)),
66};
67
5168pub const base64_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".*;
5269
5370/// Base64 encoder, replacing the standard `+/` with `-_` so that it can be used in a file name on any filesystem.
lib/std/os/windows.zig+6
......@@ -2977,6 +2977,12 @@ pub const PMEMORY_BASIC_INFORMATION = *MEMORY_BASIC_INFORMATION;
29772977/// from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
29782978pub const PATH_MAX_WIDE = 32767;
29792979
2980/// > [Each file name component can be] up to the value returned in the
2981/// > lpMaximumComponentLength parameter of the GetVolumeInformation function
2982/// > (this value is commonly 255 characters)
2983/// from https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
2984pub const NAME_MAX = 255;
2985
29802986pub const FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
29812987pub const FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000;
29822988pub const FORMAT_MESSAGE_FROM_HMODULE = 0x00000800;