authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-11 11:00:19-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-11 11:00:19-07:00
log3d89ff51300454467a39427b938110afe2d1039c
tree5487ca931cda98e814fd8b01cbfd89f4c276c024
parentb65a88416974e697f1cf2402ca7550f6225f8d39

std.fs.path: revert recent public API change

41fd343508880ffdfbc83c7b053237da09199f02 made a breaking change to the public API; this commit reverts the API changes but keeps the improved logic.

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

lib/std/fs/path.zig+14-8
...@@ -12,13 +12,19 @@ const fs = std.fs;...@@ -12,13 +12,19 @@ const fs = std.fs;
12const process = std.process;12const process = std.process;
13const native_os = builtin.target.os.tag;13const native_os = builtin.target.os.tag;
1414
15pub const sep_windows_uefi = '\\';15pub const sep_windows = '\\';
16pub const sep_posix = '/';16pub const sep_posix = '/';
17pub const sep = if (native_os == .windows or native_os == .uefi) sep_windows_uefi else sep_posix;17pub const sep = switch (native_os) {
18 .windows, .uefi => sep_windows,
19 else => sep_posix,
20};
1821
19pub const sep_str_windows_uefi = "\\";22pub const sep_str_windows = "\\";
20pub const sep_str_posix = "/";23pub const sep_str_posix = "/";
21pub const sep_str = if (native_os == .windows or native_os == .uefi) sep_str_windows_uefi else sep_str_posix;24pub const sep_str = switch (native_os) {
25 .windows, .uefi => sep_str_windows,
26 else => sep_str_posix,
27};
2228
23pub const delimiter_windows = ';';29pub const delimiter_windows = ';';
24pub const delimiter_posix = ':';30pub const delimiter_posix = ':';
...@@ -116,7 +122,7 @@ fn testJoinMaybeZUefi(paths: []const []const u8, expected: []const u8, zero: boo...@@ -116,7 +122,7 @@ fn testJoinMaybeZUefi(paths: []const []const u8, expected: []const u8, zero: boo
116 return byte == '\\';122 return byte == '\\';
117 }123 }
118 }.isSep;124 }.isSep;
119 const actual = try joinSepMaybeZ(testing.allocator, sep_windows_uefi, uefiIsSep, paths, zero);125 const actual = try joinSepMaybeZ(testing.allocator, sep_windows, uefiIsSep, paths, zero);
120 defer testing.allocator.free(actual);126 defer testing.allocator.free(actual);
121 try testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);127 try testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);
122}128}
...@@ -127,7 +133,7 @@ fn testJoinMaybeZWindows(paths: []const []const u8, expected: []const u8, zero:...@@ -127,7 +133,7 @@ fn testJoinMaybeZWindows(paths: []const []const u8, expected: []const u8, zero:
127 return byte == '/' or byte == '\\';133 return byte == '/' or byte == '\\';
128 }134 }
129 }.isSep;135 }.isSep;
130 const actual = try joinSepMaybeZ(testing.allocator, sep_windows_uefi, windowsIsSep, paths, zero);136 const actual = try joinSepMaybeZ(testing.allocator, sep_windows, windowsIsSep, paths, zero);
131 defer testing.allocator.free(actual);137 defer testing.allocator.free(actual);
132 try testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);138 try testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);
133}139}
...@@ -604,7 +610,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {...@@ -604,7 +610,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {
604 result[0] = asciiUpper(result[0]);610 result[0] = asciiUpper(result[0]);
605 // Remove the trailing slash if present, eg. if the cwd is a root611 // Remove the trailing slash if present, eg. if the cwd is a root
606 // directory.612 // directory.
607 if (cwd.len > 0 and cwd[cwd.len - 1] == sep_windows_uefi) {613 if (cwd.len > 0 and cwd[cwd.len - 1] == sep_windows) {
608 result_index -= 1;614 result_index -= 1;
609 }615 }
610 }616 }
...@@ -641,7 +647,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {...@@ -641,7 +647,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {
641 break;647 break;
642 }648 }
643 } else {649 } else {
644 result[result_index] = sep_windows_uefi;650 result[result_index] = sep_windows;
645 result_index += 1;651 result_index += 1;
646 mem.copy(u8, result[result_index..], component);652 mem.copy(u8, result[result_index..], component);
647 result_index += component.len;653 result_index += component.len;
lib/std/os/uefi.zig+1-1
...@@ -8,7 +8,7 @@ pub const Status = @import("uefi/status.zig").Status;...@@ -8,7 +8,7 @@ pub const Status = @import("uefi/status.zig").Status;
8pub const tables = @import("uefi/tables.zig");8pub const tables = @import("uefi/tables.zig");
99
10/// The memory type to allocate when using the pool10/// The memory type to allocate when using the pool
11/// Defaults to .LoaderData, the default data allocation type 11/// Defaults to .LoaderData, the default data allocation type
12/// used by UEFI applications to allocate pool memory.12/// used by UEFI applications to allocate pool memory.
13pub var efi_pool_memory_type: tables.MemoryType = .LoaderData;13pub var efi_pool_memory_type: tables.MemoryType = .LoaderData;
14pub const pool_allocator = @import("uefi/pool_allocator.zig").pool_allocator;14pub const pool_allocator = @import("uefi/pool_allocator.zig").pool_allocator;