Function realpathW [src]

Windows-only. Same as Dir.realpath except pathname is WTF16 LE encoded. The result is encoded as WTF-8. See also Dir.realpath, realpathW.

Prototype

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

Parameters

self: Dirpathname: []const u16out_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 realpathW(self: Dir, pathname: []const u16, out_buffer: []u8) RealPathError![]u8 { const w = windows; const access_mask = w.GENERIC_READ | w.SYNCHRONIZE; const share_access = w.FILE_SHARE_READ | w.FILE_SHARE_WRITE | w.FILE_SHARE_DELETE; const creation = w.FILE_OPEN; const h_file = blk: { const res = w.OpenFile(pathname, .{ .dir = self.fd, .access_mask = access_mask, .share_access = share_access, .creation = creation, .filter = .any, }) catch |err| switch (err) { error.WouldBlock => unreachable, else => |e| return e, }; break :blk res; }; defer w.CloseHandle(h_file); var wide_buf: [w.PATH_MAX_WIDE]u16 = undefined; const wide_slice = try w.GetFinalPathNameByHandle(h_file, .{}, &wide_buf); var big_out_buf: [fs.max_path_bytes]u8 = undefined; const end_index = std.unicode.wtf16LeToWtf8(&big_out_buf, wide_slice); if (end_index > out_buffer.len) return error.NameTooLong; const result = out_buffer[0..end_index]; @memcpy(result, big_out_buf[0..end_index]); return result; }