authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-14 18:26:54-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-19 12:39:36-07:00
log414641eb95cd006f4f291d259fe912885050bd2c
tree33be7ad3250e9b1aea37599828767b28f560076e
parentba0cfda93dabd07ded441ecf475fc28a90bd495e

std.fs.path.resolvePosix: avoid deprecated managed array list API


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

lib/std/fs/path.zig+16-16
......@@ -1093,23 +1093,23 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) Allocator
10931093 return result.toOwnedSlice(allocator);
10941094}
10951095
1096/// This function is like a series of `cd` statements executed one after another.
1097///
1098/// It resolves "." and ".." to the best of its ability, but will not convert relative paths to
1099/// an absolute path, use Io.Dir.realpath instead.
1096/// Simulates a series of relative directory changes on a virtual filesystem
1097/// that has no symlinks.
11001098///
1101/// ".." components may persist in the resolved path if the resolved path is relative.
1099/// "." and ".." are resolved but will not make relative paths absolute. ".."
1100/// components remain in the resolved path when the resolved path is relative
1101/// and there are not previous components to cancel out.
11021102///
11031103/// The result does not have a trailing path separator.
11041104///
11051105/// This function does not perform any syscalls. Executing this series of path
1106/// lookups on the actual filesystem may produce different results due to
1106/// lookups on an actual filesystem may produce different results due to
11071107/// symlinks.
1108pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.Error![]u8 {
1108pub fn resolvePosix(gpa: Allocator, paths: []const []const u8) Allocator.Error![]u8 {
11091109 assert(paths.len > 0);
11101110
1111 var result = std.array_list.Managed(u8).init(allocator);
1112 defer result.deinit();
1111 var result: std.ArrayList(u8) = .empty;
1112 defer result.deinit(gpa);
11131113
11141114 var negative_count: usize = 0;
11151115 var is_abs = false;
......@@ -1135,23 +1135,23 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E
11351135 if (ends_with_slash or result.items.len == 0) break;
11361136 }
11371137 } else if (result.items.len > 0 or is_abs) {
1138 try result.ensureUnusedCapacity(1 + component.len);
1138 try result.ensureUnusedCapacity(gpa, 1 + component.len);
11391139 result.appendAssumeCapacity('/');
11401140 result.appendSliceAssumeCapacity(component);
11411141 } else {
1142 try result.appendSlice(component);
1142 try result.appendSlice(gpa, component);
11431143 }
11441144 }
11451145 }
11461146
11471147 if (result.items.len == 0) {
11481148 if (is_abs) {
1149 return allocator.dupe(u8, "/");
1149 return gpa.dupe(u8, "/");
11501150 }
11511151 if (negative_count == 0) {
1152 return allocator.dupe(u8, ".");
1152 return gpa.dupe(u8, ".");
11531153 } else {
1154 const real_result = try allocator.alloc(u8, 3 * negative_count - 1);
1154 const real_result = try gpa.alloc(u8, 3 * negative_count - 1);
11551155 var count = negative_count - 1;
11561156 var i: usize = 0;
11571157 while (count > 0) : (count -= 1) {
......@@ -1164,9 +1164,9 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E
11641164 }
11651165
11661166 if (negative_count == 0) {
1167 return result.toOwnedSlice();
1167 return result.toOwnedSlice(gpa);
11681168 } else {
1169 const real_result = try allocator.alloc(u8, 3 * negative_count + result.items.len);
1169 const real_result = try gpa.alloc(u8, 3 * negative_count + result.items.len);
11701170 var count = negative_count;
11711171 var i: usize = 0;
11721172 while (count > 0) : (count -= 1) {