Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

getAlloc

Caller owns returned memory.

On Windows:

On other platforms, the value is an opaque sequence of bytes with no particular encoding.

See also:

Environ.getAlloc
pub fn getAlloc(environ: Environ, gpa: Allocator, key: []const u8) GetAllocError![]u8

File

lib/std/process/Environ.zig:713

Code

pub fn getAlloc(environ: Environ, gpa: Allocator, key: []const u8) GetAllocError![]u8 {
    if (native_os == .windows and !unicode.wtf8ValidateSlice(key)) return error.InvalidWtf8;
    var map = createMap(environ, gpa) catch return error.OutOfMemory;
    defer map.deinit();
    const val = map.get(key) orelse return error.EnvironmentVariableMissing;
    return gpa.dupe(u8, val);
}