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 › fileTryLock
fileTryLock
Dispatch.fileTryLock
fn fileTryLock (userdata : ?*anyopaque , file : File , lock : File .Lock ) File .LockError !bool
File
Code
fn fileTryLock (userdata : ?*anyopaque , file : File , lock : File .Lock ) File .LockError !bool {
const ev : *Evented = @ptrCast (@alignCast (userdata ));
_ = ev ;
const operation : i32 = switch (lock ) {
.none => c .LOCK .UN ,
.shared => c .LOCK .SH | c .LOCK .NB ,
.exclusive => c .LOCK .EX | c .LOCK .NB ,
};
while (true ) switch (c .errno (c .flock (file .handle , operation ))) {
.SUCCESS => return true ,
.INTR => {},
.AGAIN => return false ,
.BADF => |err | return errnoBug (err ),
.INVAL => |err | return errnoBug (err ),
.NOLCK => return error .SystemResources ,
.OPNOTSUPP => return error .FileLocksUnsupported ,
else => |err | return unexpectedErrno (err ),
};
}