Skip to content

Commit b2cc408

Browse files
committed
std.process: Allow WTF-8 in env var functions with comptime-known keys
1 parent 423761b commit b2cc408

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/std/process.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
423423
pub 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.
435435
pub 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.
455455
pub 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) {

0 commit comments

Comments
 (0)