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 › getDevNullFd Private Function getDevNullFd Doc Source Private Function std.Io.Threaded.getDevNullFd
fn getDevNullFd (t : *Threaded ) !posix .fd_t Params File Io/Threaded.zig: 15350
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388 fn getDevNullFd (t : *Threaded ) !posix .fd_t {
{
mutexLock (&t .mutex );
defer mutexUnlock (&t .mutex );
if (t .null_file .fd != -1 ) return t .null_file .fd ;
}
const mode : u32 = 0 ;
const syscall : Syscall = try .start ();
while (true ) {
const rc = open_sym ("/dev/null" , .{ .ACCMODE = .RDWR }, mode );
switch (posix .errno (rc )) {
.SUCCESS => {
syscall .finish ();
const fresh_fd : posix .fd_t = @intCast (rc );
mutexLock (&t .mutex ); // Another thread might have won the race.
defer mutexUnlock (&t .mutex );
if (t .null_file .fd != -1 ) {
closeFd (fresh_fd );
return t .null_file .fd ;
} else {
t .null_file .fd = fresh_fd ;
return fresh_fd ;
}
},
.INTR => {
try syscall .checkCancel ();
continue ;
},
.ACCES => return syscall .fail (error .AccessDenied ),
.MFILE => return syscall .fail (error .ProcessFdQuotaExceeded ),
.NFILE => return syscall .fail (error .SystemFdQuotaExceeded ),
.NODEV => return syscall .fail (error .NoDevice ),
.NOENT => return syscall .fail (error .FileNotFound ),
.NOMEM => return syscall .fail (error .SystemResources ),
.PERM => return syscall .fail (error .PermissionDenied ),
else => |err | return syscall .unexpectedErrno (err ),
}
}
}