authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2025-03-17 17:24:00-07:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2025-03-17 17:53:38-07:00
logb2cc408a3e5ae0f8c2550c8828f6d388c6969b5a
treee2a0e1f2c3703250c95eafda8de0395f88104598
parent423761bb6de68bec9482dbc3b3c21b2b5c74a2b9

std.process: Allow WTF-8 in env var functions with comptime-known keys


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

lib/std/process.zig+6-6
......@@ -419,10 +419,10 @@ pub fn getEnvVarOwned(allocator: Allocator, key: []const u8) GetEnvVarOwnedError
419419 }
420420}
421421
422/// On Windows, `key` must be valid UTF-8.
422/// On Windows, `key` must be valid WTF-8.
423423pub fn hasEnvVarConstant(comptime key: []const u8) bool {
424424 if (native_os == .windows) {
425 const key_w = comptime unicode.utf8ToUtf16LeStringLiteral(key);
425 const key_w = comptime unicode.wtf8ToWtf16LeStringLiteral(key);
426426 return getenvW(key_w) != null;
427427 } else if (native_os == .wasi and !builtin.link_libc) {
428428 @compileError("hasEnvVarConstant is not supported for WASI without libc");
......@@ -431,10 +431,10 @@ pub fn hasEnvVarConstant(comptime key: []const u8) bool {
431431 }
432432}
433433
434/// On Windows, `key` must be valid UTF-8.
434/// On Windows, `key` must be valid WTF-8.
435435pub fn hasNonEmptyEnvVarConstant(comptime key: []const u8) bool {
436436 if (native_os == .windows) {
437 const key_w = comptime unicode.utf8ToUtf16LeStringLiteral(key);
437 const key_w = comptime unicode.wtf8ToWtf16LeStringLiteral(key);
438438 const value = getenvW(key_w) orelse return false;
439439 return value.len != 0;
440440 } else if (native_os == .wasi and !builtin.link_libc) {
......@@ -451,10 +451,10 @@ pub const ParseEnvVarIntError = std.fmt.ParseIntError || error{EnvironmentVariab
451451///
452452/// Since the key is comptime-known, no allocation is needed.
453453///
454/// On Windows, `key` must be valid UTF-8.
454/// On Windows, `key` must be valid WTF-8.
455455pub fn parseEnvVarInt(comptime key: []const u8, comptime I: type, base: u8) ParseEnvVarIntError!I {
456456 if (native_os == .windows) {
457 const key_w = comptime std.unicode.utf8ToUtf16LeStringLiteral(key);
457 const key_w = comptime std.unicode.wtf8ToWtf16LeStringLiteral(key);
458458 const text = getenvW(key_w) orelse return error.EnvironmentVariableNotFound;
459459 return std.fmt.parseIntWithGenericCharacter(I, u16, text, base);
460460 } else if (native_os == .wasi and !builtin.link_libc) {