authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2022-12-17 19:58:53-08:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2022-12-17 22:06:47-08:00
log6e22b63edb8f87144b93dfd593e162f7c4129e8e
tree27fb1583d4d28c0d55aacc5ec6193841ab74a65e
parent901c3e96368bd9fa9ee9858c0295ee05ef1d7146

windows: Extract RtlEqualUnicodeString usage into to a helper function


2 files changed, 18 insertions(+), 13 deletions(-)

lib/std/os.zig+1-13
......@@ -1944,19 +1944,7 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {
19441944 while (ptr[i] != 0) : (i += 1) {}
19451945 const this_value = ptr[value_start..i :0];
19461946
1947 const key_string_bytes = @intCast(u16, key_slice.len * 2);
1948 const key_string = windows.UNICODE_STRING{
1949 .Length = key_string_bytes,
1950 .MaximumLength = key_string_bytes,
1951 .Buffer = @intToPtr([*]u16, @ptrToInt(key)),
1952 };
1953 const this_key_string_bytes = @intCast(u16, this_key.len * 2);
1954 const this_key_string = windows.UNICODE_STRING{
1955 .Length = this_key_string_bytes,
1956 .MaximumLength = this_key_string_bytes,
1957 .Buffer = this_key.ptr,
1958 };
1959 if (windows.ntdll.RtlEqualUnicodeString(&key_string, &this_key_string, windows.TRUE) == windows.TRUE) {
1947 if (windows.eqlIgnoreCaseWTF16(key_slice, this_key)) {
19601948 return this_value;
19611949 }
19621950
lib/std/os/windows.zig+17
......@@ -1824,6 +1824,23 @@ pub fn nanoSecondsToFileTime(ns: i128) FILETIME {
18241824 };
18251825}
18261826
1827/// Compares two WTF16 strings using RtlEqualUnicodeString
1828pub fn eqlIgnoreCaseWTF16(a: []const u16, b: []const u16) bool {
1829 const a_bytes = @intCast(u16, a.len * 2);
1830 const a_string = UNICODE_STRING{
1831 .Length = a_bytes,
1832 .MaximumLength = a_bytes,
1833 .Buffer = @intToPtr([*]u16, @ptrToInt(a.ptr)),
1834 };
1835 const b_bytes = @intCast(u16, b.len * 2);
1836 const b_string = UNICODE_STRING{
1837 .Length = b_bytes,
1838 .MaximumLength = b_bytes,
1839 .Buffer = @intToPtr([*]u16, @ptrToInt(b.ptr)),
1840 };
1841 return ntdll.RtlEqualUnicodeString(&a_string, &b_string, TRUE) == TRUE;
1842}
1843
18271844pub const PathSpace = struct {
18281845 data: [PATH_MAX_WIDE:0]u16,
18291846 len: usize,