aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorRyan Liptak <squeek502@hotmail.com>2025-10-10 03:53:12 -0700
committerRyan Liptak <squeek502@hotmail.com>2025-10-10 12:13:35 -0700
commitd629a146f5d3a487fa666c0a51f9e0683dde76b8 (patch)
tree58bc780c2490f80521400bda706cfdb6f3de3bd1 /lib/std
parent9aeabad519159a89220e475a6a544cd7d3a5db37 (diff)
downloadzig-d629a146f5d3a487fa666c0a51f9e0683dde76b8.tar.gz
zig-d629a146f5d3a487fa666c0a51f9e0683dde76b8.zip
Dir.realpathW: remove redundant buffer/copy
This same change was applied in 69007f096177143086e28da0dc1a0eff4efcc52c but accidentally reverted in 7bf740ee718f4b6109cd9fe7014d1784d48ada48
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/fs/Dir.zig13
1 files changed, 5 insertions, 8 deletions
diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig
index 7c5be3003e..eb033b698d 100644
--- a/lib/std/fs/Dir.zig
+++ b/lib/std/fs/Dir.zig
@@ -1433,16 +1433,13 @@ pub fn realpathZ(self: Dir, pathname: [*:0]const u8, out_buffer: []u8) RealPathE
/// See also `Dir.realpath`, `realpathW`.
pub fn realpathW(self: Dir, pathname: []const u16, out_buffer: []u8) RealPathError![]u8 {
var wide_buf: [std.os.windows.PATH_MAX_WIDE]u16 = undefined;
-
const wide_slice = try self.realpathW2(pathname, &wide_buf);
- var big_out_buf: [fs.max_path_bytes]u8 = undefined;
- const end_index = std.unicode.wtf16LeToWtf8(&big_out_buf, wide_slice);
- if (end_index > out_buffer.len)
- return error.NameTooLong;
- const result = out_buffer[0..end_index];
- @memcpy(result, big_out_buf[0..end_index]);
- return result;
+ const len = std.unicode.calcWtf8Len(wide_slice);
+ if (len > out_buffer.len) return error.NameTooLong;
+
+ const end_index = std.unicode.wtf16LeToWtf8(&out_buffer, wide_slice);
+ return out_buffer[0..end_index];
}
/// Windows-only. Same as `Dir.realpath` except