diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-08-10 20:09:45 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-10 20:09:45 -0400 |
| commit | 6325d6a48628bff89b2e243e0a1b6eedf39b0ec6 (patch) | |
| tree | 54f6965f18db1a1f55e318238d15f6095bff7c23 /lib/std/os.zig | |
| parent | bc176fb7390b4d03b786bbc567448836140a67fc (diff) | |
| parent | 901bf0a2e2821caa1087b03ed308700ec9135c87 (diff) | |
| download | zig-6325d6a48628bff89b2e243e0a1b6eedf39b0ec6.tar.gz zig-6325d6a48628bff89b2e243e0a1b6eedf39b0ec6.zip | |
Merge pull request #5993 from kubkon/getpathnamebyhandle
Implement std.os.windows.GetPathNameByHandle using NT routines only
Diffstat (limited to 'lib/std/os.zig')
| -rw-r--r-- | lib/std/os.zig | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig index 06b61e8c38..04c2340cad 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -4060,7 +4060,6 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP } /// Same as `realpath` except `pathname` is UTF16LE-encoded. -/// TODO use ntdll to emulate `GetFinalPathNameByHandleW` routine pub fn realpathW(pathname: []const u16, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { const w = windows; @@ -4095,15 +4094,10 @@ pub fn realpathW(pathname: []const u16, out_buffer: *[MAX_PATH_BYTES]u8) RealPat defer w.CloseHandle(h_file); var wide_buf: [w.PATH_MAX_WIDE]u16 = undefined; - const wide_slice = try w.GetFinalPathNameByHandleW(h_file, &wide_buf, wide_buf.len, w.VOLUME_NAME_DOS); - - // Windows returns \\?\ prepended to the path. - // We strip it to make this function consistent across platforms. - const prefix = [_]u16{ '\\', '\\', '?', '\\' }; - const start_index = if (mem.startsWith(u16, wide_slice, &prefix)) prefix.len else 0; + const wide_slice = try w.GetFinalPathNameByHandle(h_file, .{}, wide_buf[0..]); // Trust that Windows gives us valid UTF-16LE. - const end_index = std.unicode.utf16leToUtf8(out_buffer, wide_slice[start_index..]) catch unreachable; + const end_index = std.unicode.utf16leToUtf8(out_buffer, wide_slice) catch unreachable; return out_buffer[0..end_index]; } |
