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 › atomicFileInit Private Function atomicFileInit Doc Source Private Function std.Io.Threaded.atomicFileInit
fn atomicFileInit (
t_io : Io ,
dest_basename : []const u8 ,
permissions : File .Permissions ,
dir : Dir ,
close_dir_on_deinit : bool ,
) Dir .CreateFileAtomicError !File .Atomic Params t_io : Io dest_basename : []const u8 permissions : File .Permissions dir : Dir close_dir_on_deinit : bool File Io/Threaded.zig: 4866
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902 fn atomicFileInit (
t_io : Io ,
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 ;
t_io .random (@ptrCast (&random_integer ));
const tmp_sub_path = std .fmt .hex (random_integer );
const file = dir .createFile (t_io , &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 ,
};
}
}