windows: Extract RtlEqualUnicodeString usage into to a helper function

This commit is contained in:
Ryan Liptak 2022-12-17 19:58:53 -08:00
parent 901c3e9636
commit 6e22b63edb
2 changed files with 18 additions and 13 deletions

View File

@ -1944,19 +1944,7 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {
while (ptr[i] != 0) : (i += 1) {}
const this_value = ptr[value_start..i :0];
const key_string_bytes = @intCast(u16, key_slice.len * 2);
const key_string = windows.UNICODE_STRING{
.Length = key_string_bytes,
.MaximumLength = key_string_bytes,
.Buffer = @intToPtr([*]u16, @ptrToInt(key)),
};
const this_key_string_bytes = @intCast(u16, this_key.len * 2);
const this_key_string = windows.UNICODE_STRING{
.Length = this_key_string_bytes,
.MaximumLength = this_key_string_bytes,
.Buffer = this_key.ptr,
};
if (windows.ntdll.RtlEqualUnicodeString(&key_string, &this_key_string, windows.TRUE) == windows.TRUE) {
if (windows.eqlIgnoreCaseWTF16(key_slice, this_key)) {
return this_value;
}

View File

@ -1824,6 +1824,23 @@ pub fn nanoSecondsToFileTime(ns: i128) FILETIME {
};
}
/// Compares two WTF16 strings using RtlEqualUnicodeString
pub fn eqlIgnoreCaseWTF16(a: []const u16, b: []const u16) bool {
const a_bytes = @intCast(u16, a.len * 2);
const a_string = UNICODE_STRING{
.Length = a_bytes,
.MaximumLength = a_bytes,
.Buffer = @intToPtr([*]u16, @ptrToInt(a.ptr)),
};
const b_bytes = @intCast(u16, b.len * 2);
const b_string = UNICODE_STRING{
.Length = b_bytes,
.MaximumLength = b_bytes,
.Buffer = @intToPtr([*]u16, @ptrToInt(b.ptr)),
};
return ntdll.RtlEqualUnicodeString(&a_string, &b_string, TRUE) == TRUE;
}
pub const PathSpace = struct {
data: [PATH_MAX_WIDE:0]u16,
len: usize,