zig

fork of https://codeberg.org/ziglang/zig
Log | Tree | Refs | README | LICENSE

commit 6e22b63edb8f87144b93dfd593e162f7c4129e8e (tree)
parent 901c3e96368bd9fa9ee9858c0295ee05ef1d7146
Author: Ryan Liptak <squeek502@hotmail.com>
Date:   Sat, 17 Dec 2022 19:58:53 -0800

windows: Extract RtlEqualUnicodeString usage into to a helper function

Diffstat:
Mlib/std/os.zig | 14+-------------
Mlib/std/os/windows.zig | 17+++++++++++++++++
2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/lib/std/os.zig b/lib/std/os.zig @@ -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; } diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig @@ -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,