Function realpath [src]

This function returns the canonicalized absolute pathname of pathname relative to this Dir. If pathname is absolute, ignores this Dir handle and returns the canonicalized absolute pathname of pathname argument. On Windows, sub_path should be encoded as WTF-8. On other platforms, sub_path is an opaque sequence of bytes with no particular encoding. On Windows, the result is encoded as WTF-8. On other platforms, the result is an opaque sequence of bytes with no particular encoding. This function is not universally supported by all platforms. Currently supported hosts are: Linux, macOS, and Windows. See also Dir.realpathZ, Dir.realpathW, and Dir.realpathAlloc.

Prototype

pub fn realpath(self: Dir, pathname: []const u8, out_buffer: []u8) RealPathError![]u8

Parameters

self: Dirpathname: []const u8out_buffer: []u8

Possible Errors

AccessDenied RealPathError
AntivirusInterference RealPathError

On Windows, antivirus software is enabled by default. It can be disabled, but Windows Update sometimes ignores the user's preference and re-enables it. When enabled, antivirus software on Windows intercepts file system operations and makes them significantly slower in addition to possibly failing with this error code.

BadPathName RealPathError
DeviceBusy RealPathError
FileNotFound RealPathError
FileSystem RealPathError
FileTooBig RealPathError
InputOutput RealPathError
InvalidWtf8 RealPathError

Windows-only; file paths provided by the user must be valid WTF-8. https://simonsapin.github.io/wtf-8/

IsDir RealPathError
NameTooLong RealPathError
NetworkNotFound RealPathError

On Windows, \\server or \\server\share was not found.

NoDevice RealPathError
NoSpaceLeft RealPathError
NotDir RealPathError
NotSupported RealPathError
PathAlreadyExists RealPathError
PermissionDenied RealPathError
PipeBusy RealPathError
ProcessFdQuotaExceeded RealPathError
SharingViolation RealPathError
SymLinkLoop RealPathError
SystemFdQuotaExceeded RealPathError
SystemResources RealPathError
Unexpected UnexpectedError

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.

UnrecognizedVolume RealPathError

On Windows, the volume does not contain a recognized file system. File system drivers might not be loaded, or the volume may be corrupt.

Source

pub fn realpath(self: Dir, pathname: []const u8, out_buffer: []u8) RealPathError![]u8 { if (native_os == .wasi) { @compileError("realpath is not available on WASI"); } if (native_os == .windows) { const pathname_w = try windows.sliceToPrefixedFileW(self.fd, pathname); return self.realpathW(pathname_w.span(), out_buffer); } const pathname_c = try posix.toPosixPath(pathname); return self.realpathZ(&pathname_c, out_buffer); }