realpathAlloc
realpath, except caller must free the returned memory.
On Windows, the result is encoded as WTF-8.
On other platforms, the result is an opaque sequence of bytes with no particular encoding.
See also Dir.realpath.
Function parameters
Parameters
Type definitions in this namespace
Types
Functions in this namespace
Functions
- updateFileAbsolute
- Same as `Dir.updateFile`, except asserts that both `source_path` and `dest_path`
- copyFileAbsolute
- Same as `Dir.copyFile`, except asserts that both `source_path` and `dest_path`
- makeDirAbsolute
- Create a new directory, based on an absolute path.
- makeDirAbsoluteZ
- Same as `makeDirAbsolute` except the parameter is null-terminated.
- makeDirAbsoluteW
- Same as `makeDirAbsolute` except the parameter is a null-terminated WTF-16 LE-encoded string.
- deleteDirAbsolute
- Same as `Dir.deleteDir` except the path is absolute.
- deleteDirAbsoluteZ
- Same as `deleteDirAbsolute` except the path parameter is null-terminated.
- deleteDirAbsoluteW
- Same as `deleteDirAbsolute` except the path parameter is WTF-16 and target OS is assumed Windows.
- renameAbsolute
- Same as `Dir.rename` except the paths are absolute.
- renameAbsoluteZ
- Same as `renameAbsolute` except the path parameters are null-terminated.
- renameAbsoluteW
- Same as `renameAbsolute` except the path parameters are WTF-16 and target OS is assumed Windows.
- rename
- Same as `Dir.rename`, except `new_sub_path` is relative to `new_dir`
- renameZ
- Same as `rename` except the parameters are null-terminated.
- renameW
- Same as `rename` except the parameters are WTF16LE, NT prefixed.
- cwd
- Returns a handle to the current working directory.
- openDirAbsolute
- Opens a directory at the given path.
- openDirAbsoluteZ
- Same as `openDirAbsolute` but the path parameter is null-terminated.
- openDirAbsoluteW
- Same as `openDirAbsolute` but the path parameter is null-terminated.
- openFileAbsolute
- Opens a file for reading or writing, without attempting to create a new file, based on an absolute path.
- openFileAbsoluteZ
- Same as `openFileAbsolute` but the path parameter is null-terminated.
- openFileAbsoluteW
- Same as `openFileAbsolute` but the path parameter is WTF-16-encoded.
- accessAbsolute
- Test accessing `path`.
- accessAbsoluteZ
- Same as `accessAbsolute` but the path parameter is null-terminated.
- accessAbsoluteW
- Same as `accessAbsolute` but the path parameter is WTF-16 encoded.
- createFileAbsolute
- Creates, opens, or overwrites a file with write access, based on an absolute path.
- createFileAbsoluteZ
- Same as `createFileAbsolute` but the path parameter is null-terminated.
- createFileAbsoluteW
- Same as `createFileAbsolute` but the path parameter is WTF-16 encoded.
- deleteFileAbsolute
- Delete a file name and possibly the file it refers to, based on an absolute path.
- deleteFileAbsoluteZ
- Same as `deleteFileAbsolute` except the parameter is null-terminated.
- deleteFileAbsoluteW
- Same as `deleteFileAbsolute` except the parameter is WTF-16 encoded.
- deleteTreeAbsolute
- Removes a symlink, file, or directory.
- readLinkAbsolute
- Same as `Dir.readLink`, except it asserts the path is absolute.
- readlinkAbsoluteW
- Windows-only.
- readLinkAbsoluteZ
- Same as `readLink`, except the path parameter is null-terminated.
- symLinkAbsolute
- Creates a symbolic link named `sym_link_path` which contains the string `target_path`.
- symLinkAbsoluteW
- Windows-only.
- symLinkAbsoluteZ
- Same as `symLinkAbsolute` except the parameters are null-terminated pointers.
- selfExePathAlloc
- `selfExePath` except allocates the result on the heap.
- selfExePath
- Get the path to the current executable.
- selfExeDirPathAlloc
- `selfExeDirPath` except allocates the result on the heap.
- selfExeDirPath
- Get the directory path that contains the current executable.
- realpathAlloc
- `realpath`, except caller must free the returned memory.
Error sets in this namespace
Error Sets
= switch (native_os) { .windows, .wasi => false, else => true, }
Values
- has_executable_bit
- = switch (native_os) { .windows, .wasi => false, else => true, }
- max_path_bytes
- The maximum length of a file path that the operating system will accept.
- max_name_bytes
- This represents the maximum size of a `[]u8` file name component that
- base64_alphabet
- = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".*
- base64_encoder
- Base64 encoder, replacing the standard `+/` with `-_` so that it can be used in a file name on any filesystem.
- base64_decoder
- Base64 decoder, replacing the standard `+/` with `-_` so that it can be used in a file name on any filesystem.
Source
Implementation
pub fn realpathAlloc(allocator: Allocator, pathname: []const u8) ![]u8 {
// Use of max_path_bytes here is valid as the realpath function does not
// have a variant that takes an arbitrary-size buffer.
// TODO(#4812): Consider reimplementing realpath or using the POSIX.1-2008
// NULL out parameter (GNU's canonicalize_file_name) to handle overelong
// paths. musl supports passing NULL but restricts the output to PATH_MAX
// anyway.
var buf: [max_path_bytes]u8 = undefined;
return allocator.dupe(u8, try posix.realpath(pathname, &buf));
}