authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-02 15:06:50-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-02 15:06:50-04:00
log4aa797b6bb3716759738e057e90ac607e81ce6e5
treea71b69111bbd63390e7b3a435a3f1932aaaf5fa5
parent503c4207972b1357ac11c6a6fb2e49958b68c2dc
parent8bf7cffe29b520cda094756309bca1d354af0d6b
signaturelock-open Commit is signed but in an unrecognized format.

Merge branch 'ilmaria-master'

closes #4608

1 files changed, 15 insertions(+), 1 deletions(-)

lib/std/os.zig+15-1
...@@ -1208,12 +1208,15 @@ pub fn getenvZ(key: [*:0]const u8) ?[]const u8 {...@@ -1208,12 +1208,15 @@ pub fn getenvZ(key: [*:0]const u8) ?[]const u8 {
12081208
1209/// Windows-only. Get an environment variable with a null-terminated, WTF-16 encoded name.1209/// Windows-only. Get an environment variable with a null-terminated, WTF-16 encoded name.
1210/// See also `getenv`.1210/// See also `getenv`.
1211/// This function first attempts a case-sensitive lookup. If no match is found, and `key`
1212/// is ASCII, then it attempts a second case-insensitive lookup.
1211pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {1213pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {
1212 if (builtin.os.tag != .windows) {1214 if (builtin.os.tag != .windows) {
1213 @compileError("std.os.getenvW is a Windows-only API");1215 @compileError("std.os.getenvW is a Windows-only API");
1214 }1216 }
1215 const key_slice = mem.spanZ(key);1217 const key_slice = mem.spanZ(key);
1216 const ptr = windows.peb().ProcessParameters.Environment;1218 const ptr = windows.peb().ProcessParameters.Environment;
1219 var ascii_match: ?[:0]const u16 = null;
1217 var i: usize = 0;1220 var i: usize = 0;
1218 while (ptr[i] != 0) {1221 while (ptr[i] != 0) {
1219 const key_start = i;1222 const key_start = i;
...@@ -1229,9 +1232,20 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {...@@ -1229,9 +1232,20 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {
12291232
1230 if (mem.eql(u16, key_slice, this_key)) return this_value;1233 if (mem.eql(u16, key_slice, this_key)) return this_value;
12311234
1235 ascii_check: {
1236 if (ascii_match != null) break :ascii_check;
1237 if (key_slice.len != this_key.len) break :ascii_check;
1238 for (key_slice) |a_c, key_index| {
1239 const a = math.cast(u8, a_c) catch break :ascii_check;
1240 const b = math.cast(u8, this_key[key_index]) catch break :ascii_check;
1241 if (std.ascii.toLower(a) != std.ascii.toLower(b)) break :ascii_check;
1242 }
1243 ascii_match = this_value;
1244 }
1245
1232 i += 1; // skip over null byte1246 i += 1; // skip over null byte
1233 }1247 }
1234 return null;1248 return ascii_match;
1235}1249}
12361250
1237pub const GetCwdError = error{1251pub const GetCwdError = error{