Function hasNonEmptyEnvVar [src]
On Windows, if key is not valid WTF-8,
then error.InvalidWtf8 is returned.
Prototype
pub fn hasNonEmptyEnvVar(allocator: Allocator, key: []const u8) HasEnvVarError!bool
Parameters
allocator: Allocator
key: []const u8
Possible Errors
On Windows, environment variable keys provided by the user must be valid WTF-8. https://simonsapin.github.io/wtf-8/
Source
pub fn hasNonEmptyEnvVar(allocator: Allocator, key: []const u8) HasEnvVarError!bool {
if (native_os == .windows) {
var stack_alloc = std.heap.stackFallback(256 * @sizeOf(u16), allocator);
const stack_allocator = stack_alloc.get();
const key_w = try unicode.wtf8ToWtf16LeAllocZ(stack_allocator, key);
defer stack_allocator.free(key_w);
const value = getenvW(key_w) orelse return false;
return value.len != 0;
} else if (native_os == .wasi and !builtin.link_libc) {
var envmap = getEnvMap(allocator) catch return error.OutOfMemory;
defer envmap.deinit();
const value = envmap.getPtr(key) orelse return false;
return value.len != 0;
} else {
const value = posix.getenv(key) orelse return false;
return value.len != 0;
}
}