Function readLink [src]

Read value of a symbolic link. The return value is a slice of buffer, from index 0. Asserts that the path parameter has no null bytes. 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.

Prototype

pub fn readLink(self: Dir, sub_path: []const u8, buffer: []u8) ReadLinkError![]u8

Parameters

self: Dirsub_path: []const u8buffer: []u8

Possible Errors

AccessDenied ReadLinkError

In WASI, this error may occur when the file descriptor does not hold the required rights to read value of a symbolic link relative to it.

BadPathName ReadLinkError
FileNotFound ReadLinkError
FileSystem ReadLinkError
InvalidUtf8 ReadLinkError

WASI-only; file paths must be valid UTF-8.

InvalidWtf8 ReadLinkError

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

NameTooLong ReadLinkError
NetworkNotFound ReadLinkError

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

NotDir ReadLinkError
NotLink ReadLinkError
PermissionDenied ReadLinkError
SymLinkLoop ReadLinkError
SystemResources ReadLinkError
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.

UnsupportedReparsePointType ReadLinkError

Windows-only. This error may occur if the opened reparse point is of unsupported type.

Source

pub fn readLink(self: Dir, sub_path: []const u8, buffer: []u8) ReadLinkError![]u8 { if (native_os == .wasi and !builtin.link_libc) { return self.readLinkWasi(sub_path, buffer); } if (native_os == .windows) { const sub_path_w = try windows.sliceToPrefixedFileW(self.fd, sub_path); return self.readLinkW(sub_path_w.span(), buffer); } const sub_path_c = try posix.toPosixPath(sub_path); return self.readLinkZ(&sub_path_c, buffer); }