authorgravatar for fancl20@gmail.comroot <fancl20@gmail.com> 2021-03-18 09:33:08+11:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-03-18 14:33:38+02:00
log75a7abb0c47d9f5e99b1f69250776528fa60f569
tree8696e9890cc406d69b70fd53583e108c7aeb0d36
parentbcc97bc1ed781c261ece5ff9a33ee9c1e621b62a

std: Fix std.fs.path.joinZ


1 files changed, 11 insertions(+), 1 deletions(-)

lib/std/fs/path.zig+11-1
...@@ -92,7 +92,7 @@ pub fn join(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -92,7 +92,7 @@ pub fn join(allocator: *Allocator, paths: []const []const u8) ![]u8 {
92/// Naively combines a series of paths with the native path seperator and null terminator.92/// Naively combines a series of paths with the native path seperator and null terminator.
93/// Allocates memory for the result, which must be freed by the caller.93/// Allocates memory for the result, which must be freed by the caller.
94pub fn joinZ(allocator: *Allocator, paths: []const []const u8) ![:0]u8 {94pub fn joinZ(allocator: *Allocator, paths: []const []const u8) ![:0]u8 {
95 const out = joinSepMaybeZ(allocator, sep, isSep, paths, true);95 const out = try joinSepMaybeZ(allocator, sep, isSep, paths, true);
96 return out[0 .. out.len - 1 :0];96 return out[0 .. out.len - 1 :0];
97}97}
9898
...@@ -119,6 +119,16 @@ fn testJoinMaybeZPosix(paths: []const []const u8, expected: []const u8, zero: bo...@@ -119,6 +119,16 @@ fn testJoinMaybeZPosix(paths: []const []const u8, expected: []const u8, zero: bo
119}119}
120120
121test "join" {121test "join" {
122 {
123 const actual: []u8 = try join(testing.allocator, &[_][]const u8{});
124 defer testing.allocator.free(actual);
125 testing.expectEqualSlices(u8, "", actual);
126 }
127 {
128 const actual: [:0]u8 = try joinZ(testing.allocator, &[_][]const u8{});
129 defer testing.allocator.free(actual);
130 testing.expectEqualSlices(u8, "", actual);
131 }
122 for (&[_]bool{ false, true }) |zero| {132 for (&[_]bool{ false, true }) |zero| {
123 testJoinMaybeZWindows(&[_][]const u8{}, "", zero);133 testJoinMaybeZWindows(&[_][]const u8{}, "", zero);
124 testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero);134 testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero);