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 › dirAccessWasi Private Function dirAccessWasi Doc Source Private Function std.Io.Threaded.dirAccessWasi
fn dirAccessWasi (
userdata : ?*anyopaque ,
dir : Dir ,
sub_path : []const u8 ,
options : Dir .AccessOptions ,
) Dir .AccessError !void Params userdata : ?*anyopaque dir : Dir sub_path : []const u8 options : Dir .AccessOptions File Io/Threaded.zig: 4227
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297 fn dirAccessWasi (
userdata : ?*anyopaque ,
dir : Dir ,
sub_path : []const u8 ,
options : Dir .AccessOptions ,
) Dir .AccessError !void {
if (builtin .link_libc ) return dirAccessPosix (userdata , dir , sub_path , options );
const t : *Threaded = @ptrCast (@alignCast (userdata ));
_ = t ;
const wasi = std .os .wasi ;
const flags : wasi .lookupflags_t = .{
.SYMLINK_FOLLOW = options .follow_symlinks ,
};
var stat : wasi .filestat_t = undefined ;
const syscall : Syscall = try .start ();
while (true ) {
switch (wasi .path_filestat_get (dir .handle , flags , sub_path .ptr , sub_path .len , &stat )) {
.SUCCESS => {
syscall .finish ();
break ;
},
.INTR => {
try syscall .checkCancel ();
continue ;
},
else => |e | {
syscall .finish ();
switch (e ) {
.INVAL => |err | return errnoBug (err ),
.BADF => |err | return errnoBug (err ), // File descriptor used after closed.
.NOMEM => return error .SystemResources ,
.ACCES => return error .AccessDenied ,
.FAULT => |err | return errnoBug (err ),
.NAMETOOLONG => return error .NameTooLong ,
.NOENT => return error .FileNotFound ,
.NOTDIR => return error .FileNotFound ,
.NOTCAPABLE => return error .AccessDenied ,
.ILSEQ => return error .BadPathName ,
else => |err | return posix .unexpectedErrno (err ),
}
},
}
}
if (!options .read and !options .write and !options .execute )
return ;
var directory : wasi .fdstat_t = undefined ;
if (wasi .fd_fdstat_get (dir .handle , &directory ) != .SUCCESS )
return error .AccessDenied ;
var rights : wasi .rights_t = .{};
if (options .read ) {
if (stat .filetype == .DIRECTORY ) {
rights .FD_READDIR = true ;
} else {
rights .FD_READ = true ;
}
}
if (options .write )
rights .FD_WRITE = true ;
// No validation for execution.
// https://github.com/ziglang/zig/issues/18882
const rights_int : u64 = @bitCast (rights );
const inheriting_int : u64 = @bitCast (directory .fs_rights_inheriting );
if ((rights_int & inheriting_int ) != rights_int )
return error .AccessDenied ;
}