aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/std/os.zig14
-rw-r--r--lib/std/os/windows.zig17
2 files changed, 18 insertions, 13 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig
index 3d0c7a6351..b0884cef05 100644
--- 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
index d654a60bd9..6ad3ac62b2 100644
--- 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,