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 › Dispatch › atomicFileInit Private Function atomicFileInit Doc Source Private Function std.Io.Dispatch.atomicFileInit
fn atomicFileInit (
ev : *Evented ,
dest_basename : []const u8 ,
permissions : File .Permissions ,
dir : Dir ,
close_dir_on_deinit : bool ,
) Dir .CreateFileAtomicError !File .Atomic Params ev : *Evented dest_basename : []const u8 permissions : File .Permissions dir : Dir close_dir_on_deinit : bool File Io/Dispatch.zig: 2565
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601 fn atomicFileInit (
ev : *Evented ,
dest_basename : []const u8 ,
permissions : File .Permissions ,
dir : Dir ,
close_dir_on_deinit : bool ,
) Dir .CreateFileAtomicError !File .Atomic {
while (true ) {
var random_integer : u64 = undefined ;
random (ev , @ptrCast (&random_integer ));
const tmp_sub_path = std .fmt .hex (random_integer );
const file = dirCreateFile (ev , dir , &tmp_sub_path , .{
.permissions = permissions ,
.exclusive = true ,
}) catch |err | switch (err ) {
error .PathAlreadyExists => continue ,
error .DeviceBusy => continue ,
error .FileBusy => continue ,
error .IsDir => return error .Unexpected , // No path components.
error .FileTooBig => return error .Unexpected , // Creating, not opening.
error .FileLocksUnsupported => return error .Unexpected , // Not asking for locks.
error .PipeBusy => return error .Unexpected , // Not opening a pipe.
else => |e | return e ,
};
return .{
.file = file ,
.file_basename_hex = random_integer ,
.dest_sub_path = dest_basename ,
.file_open = true ,
.file_exists = true ,
.close_dir_on_deinit = close_dir_on_deinit ,
.dir = dir ,
};
}
}