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.
Zig › std/ › Io/ › Dispatch.zig › pipe2
pipe2
Dispatch.pipe2
fn pipe2 (flags : c .O ) PipeError ![2 ]c .fd_t
File
Code
fn pipe2 (flags : c .O ) PipeError ![2 ]c .fd_t {
var fds : [2 ]c .fd_t = undefined ;
while (true ) switch (c .errno (c .pipe (&fds ))) {
.SUCCESS => break ,
.INTR => {},
.NFILE => return error .SystemFdQuotaExceeded ,
.MFILE => return error .ProcessFdQuotaExceeded ,
else => |err | return unexpectedErrno (err ),
};
errdefer {
closeFd (fds [0 ]);
closeFd (fds [1 ]);
}
if (@as (u32 , @bitCast (flags )) == 0 ) return fds ;
// F.SETFD.
if (flags .CLOEXEC ) for (fds ) |fd | while (true ) switch (c .errno (c .fcntl (fd , c .F .SETFD , @as (u32 , c .FD_CLOEXEC )))) {
.SUCCESS => break ,
.INTR => {},
else => |err | return unexpectedErrno (err ),
};
const new_flags : u32 = f : {
var new_flags = flags ;
new_flags .CLOEXEC = false ;
break :f @bitCast (new_flags );
};
if (new_flags != 0 ) for (fds ) |fd | while (true ) switch (c .errno (c .fcntl (fd , c .F .SETFL , new_flags ))) {
.SUCCESS => break ,
.INTR => {},
.INVAL => |err | return errnoBug (err ),
else => |err | return unexpectedErrno (err ),
};
return fds ;
}