aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2020-08-05 17:23:35 +0200
committerJakub Konka <kubkon@jakubkonka.com>2020-08-06 23:56:37 +0200
commit747d46f22c2b5bef2d111564b5e4d362228004a2 (patch)
treed9a45754752c08ce8cd3ebc4e03d2a06347a3055 /lib/std/os.zig
parenta2bb246db4c2bb88f402215d5db79a535dbff4b6 (diff)
downloadzig-747d46f22c2b5bef2d111564b5e4d362228004a2.tar.gz
zig-747d46f22c2b5bef2d111564b5e4d362228004a2.zip
Initial draft of GetFinalPathNameByHandle
This commit proposes an initial draft of `GetPathNameByHandle` function which wraps NT syscalls and strives to emulate (currently only partially) the `kernel32.GetFinalPathNameByHandleW` function.
Diffstat (limited to 'lib/std/os.zig')
-rw-r--r--lib/std/os.zig10
1 files changed, 2 insertions, 8 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig
index 06b61e8c38..88ce77dc56 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];
}