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 standard library.
std › process › Preopens › init Public Function init Doc Source 49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 pub fn init (arena : Allocator ) InitError !Preopens {
if (native_os != .wasi ) return .{ .map = {} };
const wasi = std .os .wasi ;
var map : Map = .empty ;
try map .ensureUnusedCapacity (arena , 3 );
map .putAssumeCapacityNoClobber ("stdin" , {}); // 0
map .putAssumeCapacityNoClobber ("stdout" , {}); // 1
map .putAssumeCapacityNoClobber ("stderr" , {}); // 2
while (true ) {
const fd : wasi .fd_t = @intCast (map .entries .len );
var prestat : wasi .prestat_t = undefined ;
switch (wasi .fd_prestat_get (fd , &prestat )) {
.SUCCESS => {},
.OPNOTSUPP , .BADF => return .{ .map = map },
else => return error .Unexpected ,
}
try map .ensureUnusedCapacity (arena , 1 );
// This length does not include a null byte. Let's keep it this way to
// gently encourage WASI implementations to behave properly.
const name_len = prestat .u .dir .pr_name_len ;
const name = try arena .alloc (u8 , name_len );
switch (wasi .fd_prestat_dir_name (fd , name .ptr , name .len )) {
.SUCCESS => {},
else => return error .Unexpected ,
}
map .putAssumeCapacityNoClobber (name , {});
}
}