Function access [src]
Test accessing sub_path.
On Windows, sub_path should be encoded as WTF-8.
On WASI, sub_path should be encoded as valid UTF-8.
On other platforms, sub_path is an opaque sequence of bytes with no particular encoding.
Be careful of Time-Of-Check-Time-Of-Use race conditions when using this function.
For example, instead of testing if a file exists and then opening it, just
open it and handle the error for file not found.
Prototype
pub fn access(self: Dir, sub_path: []const u8, flags: File.OpenFlags) AccessError!void
Parameters
self: Dir
sub_path: []const u8
flags: File.OpenFlags
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/
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 access(self: Dir, sub_path: []const u8, flags: File.OpenFlags) AccessError!void {
if (native_os == .windows) {
const sub_path_w = try windows.sliceToPrefixedFileW(self.fd, sub_path);
return self.accessW(sub_path_w.span().ptr, flags);
}
const path_c = try posix.toPosixPath(sub_path);
return self.accessZ(&path_c, flags);
}