Function parseEnvVarInt [src]

Parses an environment variable as an integer. Since the key is comptime-known, no allocation is needed. On Windows, key must be valid UTF-8.

Prototype

pub fn parseEnvVarInt(comptime key: []const u8, comptime I: type, base: u8) ParseEnvVarIntError!I

Parameters

key: []const u8I: typebase: u8

Possible Errors

EnvironmentVariableNotFound
InvalidCharacter ParseIntError

The input was empty or contained an invalid character

Overflow ParseIntError

The result cannot fit in the type specified

Source

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 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) { @compileError("parseEnvVarInt is not supported for WASI without libc"); } else { const text = posix.getenv(key) orelse return error.EnvironmentVariableNotFound; return std.fmt.parseInt(I, text, base); } }