aboutsummaryrefslogtreecommitdiff
path: root/lib/std/fs
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-11-30 01:44:34 -0500
committerGitHub <noreply@github.com>2022-11-30 01:44:34 -0500
commite35f297aeb993ec956ae80379ddf7f86069e109b (patch)
tree45cbb5b3ebbe23a46e27b04aa5898a6c00ec4a61 /lib/std/fs
parentdeda6b514691c3a7ffc7931469886d0e7be2f67e (diff)
parentf4666678886c2a7a993ad30b63de4ff25594085a (diff)
downloadzig-e35f297aeb993ec956ae80379ddf7f86069e109b.tar.gz
zig-e35f297aeb993ec956ae80379ddf7f86069e109b.zip
Merge pull request #13666 from ziglang/allocator-interface
std.mem.Allocator: allow shrink to fail
Diffstat (limited to 'lib/std/fs')
-rw-r--r--lib/std/fs/file.zig6
-rw-r--r--lib/std/fs/path.zig2
-rw-r--r--lib/std/fs/wasi.zig6
3 files changed, 6 insertions, 8 deletions
diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig
index 0b5ba6de0b..a1e81c9b94 100644
--- a/lib/std/fs/file.zig
+++ b/lib/std/fs/file.zig
@@ -954,11 +954,9 @@ pub const File = struct {
};
if (optional_sentinel) |sentinel| {
- try array_list.append(sentinel);
- const buf = array_list.toOwnedSlice();
- return buf[0 .. buf.len - 1 :sentinel];
+ return try array_list.toOwnedSliceSentinel(sentinel);
} else {
- return array_list.toOwnedSlice();
+ return try array_list.toOwnedSlice();
}
}
diff --git a/lib/std/fs/path.zig b/lib/std/fs/path.zig
index f4b5a3cf6e..91244e34bd 100644
--- a/lib/std/fs/path.zig
+++ b/lib/std/fs/path.zig
@@ -1155,7 +1155,7 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]
}
if (to_rest.len == 0) {
// shave off the trailing slash
- return allocator.shrink(result, result_index - 1);
+ return allocator.realloc(result, result_index - 1);
}
mem.copy(u8, result[result_index..], to_rest);
diff --git a/lib/std/fs/wasi.zig b/lib/std/fs/wasi.zig
index 6358873ede..706cec905e 100644
--- a/lib/std/fs/wasi.zig
+++ b/lib/std/fs/wasi.zig
@@ -160,7 +160,7 @@ pub const PreopenList = struct {
if (cwd_root) |root| assert(fs.path.isAbsolute(root));
// Clear contents if we're being called again
- for (self.toOwnedSlice()) |preopen| {
+ for (try self.toOwnedSlice()) |preopen| {
switch (preopen.type) {
PreopenType.Dir => |path| self.buffer.allocator.free(path),
}
@@ -263,8 +263,8 @@ pub const PreopenList = struct {
}
/// The caller owns the returned memory. ArrayList becomes empty.
- pub fn toOwnedSlice(self: *Self) []Preopen {
- return self.buffer.toOwnedSlice();
+ pub fn toOwnedSlice(self: *Self) ![]Preopen {
+ return try self.buffer.toOwnedSlice();
}
};