diff options
| author | Ryan Liptak <squeek502@hotmail.com> | 2025-03-17 17:24:00 -0700 |
|---|---|---|
| committer | Ryan Liptak <squeek502@hotmail.com> | 2025-03-17 17:53:38 -0700 |
| commit | b2cc408a3e5ae0f8c2550c8828f6d388c6969b5a (patch) | |
| tree | e2a0e1f2c3703250c95eafda8de0395f88104598 /lib/std/process.zig | |
| parent | 423761bb6de68bec9482dbc3b3c21b2b5c74a2b9 (diff) | |
| download | zig-b2cc408a3e5ae0f8c2550c8828f6d388c6969b5a.tar.gz zig-b2cc408a3e5ae0f8c2550c8828f6d388c6969b5a.zip | |
std.process: Allow WTF-8 in env var functions with comptime-known keys
Diffstat (limited to 'lib/std/process.zig')
| -rw-r--r-- | lib/std/process.zig | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/std/process.zig b/lib/std/process.zig index 4efb58c3df..26b25b25fe 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -419,10 +419,10 @@ pub fn getEnvVarOwned(allocator: Allocator, key: []const u8) GetEnvVarOwnedError } } -/// On Windows, `key` must be valid UTF-8. +/// On Windows, `key` must be valid WTF-8. pub fn hasEnvVarConstant(comptime key: []const u8) bool { if (native_os == .windows) { - const key_w = comptime unicode.utf8ToUtf16LeStringLiteral(key); + const key_w = comptime unicode.wtf8ToWtf16LeStringLiteral(key); return getenvW(key_w) != null; } else if (native_os == .wasi and !builtin.link_libc) { @compileError("hasEnvVarConstant is not supported for WASI without libc"); @@ -431,10 +431,10 @@ pub fn hasEnvVarConstant(comptime key: []const u8) bool { } } -/// On Windows, `key` must be valid UTF-8. +/// On Windows, `key` must be valid WTF-8. pub fn hasNonEmptyEnvVarConstant(comptime key: []const u8) bool { if (native_os == .windows) { - const key_w = comptime unicode.utf8ToUtf16LeStringLiteral(key); + const key_w = comptime unicode.wtf8ToWtf16LeStringLiteral(key); const value = getenvW(key_w) orelse return false; return value.len != 0; } else if (native_os == .wasi and !builtin.link_libc) { @@ -451,10 +451,10 @@ pub const ParseEnvVarIntError = std.fmt.ParseIntError || error{EnvironmentVariab /// /// Since the key is comptime-known, no allocation is needed. /// -/// On Windows, `key` must be valid UTF-8. +/// On Windows, `key` must be valid WTF-8. pub fn parseEnvVarInt(comptime key: []const u8, comptime I: type, base: u8) ParseEnvVarIntError!I { if (native_os == .windows) { - const key_w = comptime std.unicode.utf8ToUtf16LeStringLiteral(key); + const key_w = comptime std.unicode.wtf8ToWtf16LeStringLiteral(key); const text = getenvW(key_w) orelse return error.EnvironmentVariableNotFound; return std.fmt.parseIntWithGenericCharacter(I, u16, text, base); } else if (native_os == .wasi and !builtin.link_libc) { |
