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 › Io › Threaded › pipe2 Public Function pipe2 Doc Source Public Function std.Io.Threaded.pipe2
pub fn pipe2 (flags : posix .O ) PipeError ![2 ]posix .fd_t Params File Io/Threaded.zig: 18229
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281 pub fn pipe2 (flags : posix .O ) PipeError ![2 ]posix .fd_t {
var fds : [2 ]posix .fd_t = undefined ;
if (@TypeOf (posix .system .pipe2 ) != void ) {
switch (posix .errno (posix .system .pipe2 (&fds , flags ))) {
.SUCCESS => return fds ,
.INVAL => |err | return errnoBug (err ), // Invalid flags
.NFILE => return error .SystemFdQuotaExceeded ,
.MFILE => return error .ProcessFdQuotaExceeded ,
else => |err | return posix .unexpectedErrno (err ),
}
}
switch (posix .errno (posix .system .pipe (&fds ))) {
.SUCCESS => {},
.NFILE => return error .SystemFdQuotaExceeded ,
.MFILE => return error .ProcessFdQuotaExceeded ,
else => |err | return posix .unexpectedErrno (err ),
}
errdefer {
closeFd (fds [0 ]);
closeFd (fds [1 ]);
}
// https://github.com/ziglang/zig/issues/18882
if (@as (u32 , @bitCast (flags )) == 0 ) return fds ;
// CLOEXEC is special, it's a file descriptor flag and must be set using
// F.SETFD.
if (flags .CLOEXEC ) for (fds ) |fd | {
switch (posix .errno (posix .system .fcntl (fd , posix .F .SETFD , @as (u32 , posix .FD_CLOEXEC )))) {
.SUCCESS => {},
else => |err | return posix .unexpectedErrno (err ),
}
};
const new_flags : u32 = f : {
var new_flags = flags ;
new_flags .CLOEXEC = false ;
break :f @bitCast (new_flags );
};
// Set every other flag affecting the file status using F.SETFL.
if (new_flags != 0 ) for (fds ) |fd | {
switch (posix .errno (posix .system .fcntl (fd , posix .F .SETFL , new_flags ))) {
.SUCCESS => {},
.INVAL => |err | return errnoBug (err ),
else => |err | return posix .unexpectedErrno (err ),
}
};
return fds ;
}