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.

get

Preopens.get
pub fn get(p: *const Preopens, name: []const u8) ?Resource

File

lib/std/process/Preopens.zig:28

Code

pub fn get(p: *const Preopens, name: []const u8) ?Resource {
    switch (native_os) {
        .wasi => {
            const index = p.map.getIndex(name) orelse return null;
            if (index <= 2) return .{ .file = .{
                .handle = @intCast(index),
                .flags = .{ .nonblocking = false },
            } };
            return .{ .dir = .{ .handle = @intCast(index) } };
        },
        else => {
            if (std.mem.eql(u8, name, "stdin")) return .{ .file = .stdin() };
            if (std.mem.eql(u8, name, "stdout")) return .{ .file = .stdout() };
            if (std.mem.eql(u8, name, "stderr")) return .{ .file = .stderr() };
            return null;
        },
    }
}