Function openDirZ [src]
Same as openDir except the parameter is null-terminated.
Prototype
pub fn openDirZ(self: Dir, sub_path_c: [*:0]const u8, args: OpenOptions) OpenError!Dir
Parameters
self: Dir
sub_path_c: [*:0]const u8
args: OpenOptions
Possible Errors
WASI-only; file paths must be valid UTF-8.
Windows-only; file paths provided by the user must be valid WTF-8. https://simonsapin.github.io/wtf-8/
On Windows, \\server
or \\server\share
was not found.
The Operating System returned an undocumented error code.
This error is in theory not possible, but it would be better to handle this error than to invoke undefined behavior.
When this error code is observed, it usually means the Zig Standard Library needs a small patch to add the error code to the error set for the respective function.
Source
pub fn openDirZ(self: Dir, sub_path_c: [*:0]const u8, args: OpenOptions) OpenError!Dir {
switch (native_os) {
.windows => {
const sub_path_w = try windows.cStrToPrefixedFileW(self.fd, sub_path_c);
return self.openDirW(sub_path_w.span().ptr, args);
},
// Use the libc API when libc is linked because it implements things
// such as opening absolute directory paths.
.wasi => if (!builtin.link_libc) {
return openDir(self, mem.sliceTo(sub_path_c, 0), args);
},
.haiku => {
const rc = posix.system._kern_open_dir(self.fd, sub_path_c);
if (rc >= 0) return .{ .fd = rc };
switch (@as(posix.E, @enumFromInt(rc))) {
.FAULT => unreachable,
.INVAL => unreachable,
.BADF => unreachable,
.ACCES => return error.AccessDenied,
.LOOP => return error.SymLinkLoop,
.MFILE => return error.ProcessFdQuotaExceeded,
.NAMETOOLONG => return error.NameTooLong,
.NFILE => return error.SystemFdQuotaExceeded,
.NODEV => return error.NoDevice,
.NOENT => return error.FileNotFound,
.NOMEM => return error.SystemResources,
.NOTDIR => return error.NotDir,
.PERM => return error.PermissionDenied,
.BUSY => return error.DeviceBusy,
else => |err| return posix.unexpectedErrno(err),
}
},
else => {},
}
var symlink_flags: posix.O = switch (native_os) {
.wasi => .{
.read = true,
.NOFOLLOW = args.no_follow,
.DIRECTORY = true,
},
else => .{
.ACCMODE = .RDONLY,
.NOFOLLOW = args.no_follow,
.DIRECTORY = true,
.CLOEXEC = true,
},
};
if (@hasField(posix.O, "PATH") and !args.iterate)
symlink_flags.PATH = true;
return self.openDirFlagsZ(sub_path_c, symlink_flags);
}