~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/zlay

atproto relay in zig · mirror of https://tangled.org/zat.dev/zlay

0
0
18 lines · 703 B Raw History
//! env — process environment helpers.
//!
//! std.posix.getenv was removed in zig 0.16; this wraps libc getenv so the
//! four call sites that needed it don't each re-declare the extern shim.

const std = @import("std");

/// libc getenv — returns the value as a slice, or null if unset.
pub fn getenv(key: [*:0]const u8) ?[]const u8 {
    const ptr = std.c.getenv(key) orelse return null;
    return std.mem.sliceTo(ptr, 0);
}

/// parse an integer-valued env var, falling back to `default` if unset or unparseable.
pub fn parseEnvInt(comptime T: type, key: [*:0]const u8, default: T) T {
    const val = getenv(key) orelse return default;
    return std.fmt.parseInt(T, val, 10) catch default;
}