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 {
9292/// Naively combines a series of paths with the native path seperator and null terminator.
9393/// Allocates memory for the result, which must be freed by the caller.
9494pub 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);
9696 return out[0 .. out.len - 1 :0];
9797}
9898
......@@ -119,6 +119,16 @@ fn testJoinMaybeZPosix(paths: []const []const u8, expected: []const u8, zero: bo
119119}
120120
121121test "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 }
122132 for (&[_]bool{ false, true }) |zero| {
123133 testJoinMaybeZWindows(&[_][]const u8{}, "", zero);
124134 testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero);