| ... | ... | @@ -21,6 +21,7 @@ const assert = std.debug.assert; |
| 21 | 21 | const math = std.math; |
| 22 | 22 | const mem = std.mem; |
| 23 | 23 | const elf = std.elf; |
| 24 | const unicode = std.unicode; |
| 24 | 25 | const dl = @import("dynamic_library.zig"); |
| 25 | 26 | const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES; |
| 26 | 27 | |
| ... | ... | @@ -1206,6 +1207,19 @@ pub fn getenvZ(key: [*:0]const u8) ?[]const u8 { |
| 1206 | 1207 | return getenv(mem.spanZ(key)); |
| 1207 | 1208 | } |
| 1208 | 1209 | |
| 1210 | fn utf16LeAsciiEqlIgnoreCase(a: []const u16, b: []const u16) bool { |
| 1211 | if (a.len != b.len) return false; |
| 1212 | var a_it = unicode.Utf16LeIterator.init(a); |
| 1213 | var b_it = unicode.Utf16LeIterator.init(b); |
| 1214 | while (a_it.nextCodepoint() catch return false) |a_codepoint| { |
| 1215 | const b_codepoint = (b_it.nextCodepoint() catch return false) orelse return false; |
| 1216 | const upper_a = if (a_codepoint >= 97 and a_codepoint <= 122) a_codepoint & 0b11011111 else a_codepoint; |
| 1217 | const upper_b = if (b_codepoint >= 97 and b_codepoint <= 122) b_codepoint & 0b11011111 else b_codepoint; |
| 1218 | if (upper_a != upper_b) return false; |
| 1219 | } |
| 1220 | return true; |
| 1221 | } |
| 1222 | |
| 1209 | 1223 | /// Windows-only. Get an environment variable with a null-terminated, WTF-16 encoded name. |
| 1210 | 1224 | /// See also `getenv`. |
| 1211 | 1225 | pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 { |
| ... | ... | @@ -1227,7 +1241,7 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 { |
| 1227 | 1241 | while (ptr[i] != 0) : (i += 1) {} |
| 1228 | 1242 | const this_value = ptr[value_start..i :0]; |
| 1229 | 1243 | |
| 1230 | | if (mem.eql(u16, key_slice, this_key)) return this_value; |
| 1244 | if (utf16LeAsciiEqlIgnoreCase(key_slice, this_key)) return this_value; |
| 1231 | 1245 | |
| 1232 | 1246 | i += 1; // skip over null byte |
| 1233 | 1247 | } |