Publishing this at @kubkon 's recommendation in #11021 (comment)
That PR introduced std.os.RelativePathWasi, which looks like this:
/// An fd-relative file path
pub const RelativePathWasi = struct {
/// Handle to directory
dir_fd: fd_t,
/// Path to resource within `dir_fd`.
relative_path: []const u8,
};
Although this only used in the WASI-specific internal functions right now, it seems natural for all of the (slightly) more modern *at() POSIX functions: openat, renameat, symlinkat, etc.
The idea would be to change these functions to accept RelativePath for fd_t-relative path arguments:
// Proposed
fn openat(file: RelativePath, flags: u32, mode: mode_t) OpenError!fd_t
fn symlinkat(target: []const u8, symlink: RelativePath) SymLinkError!void
fn renameat(old: RelativePath, new: RelativePath) RenameError!void
// Current
fn openat(dir_fd: fd_t, file_path: []const u8, flags: u32, mode: mode_t) OpenError!fd_t
fn symlinkat(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void
fn renameat(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, new_path: []const u8) RenameError!void
This comes with some other small advantages:
- POSIX-style functions can be made to be generic over
fd_t/[]const u8/RelativePath parameters, if desired
- It matches the
cwd().openFile() style in the "std.fs" interface well - e.g. cwd().getRelativePath(...) could give you a RelativePath for use with the POSIX-style std.os functions
Publishing this at @kubkon 's recommendation in #11021 (comment)
That PR introduced
std.os.RelativePathWasi, which looks like this:Although this only used in the WASI-specific internal functions right now, it seems natural for all of the (slightly) more modern
*at()POSIX functions:openat,renameat,symlinkat, etc.The idea would be to change these functions to accept
RelativePathforfd_t-relative path arguments:This comes with some other small advantages:
fd_t/[]const u8/RelativePathparameters, if desiredcwd().openFile()style in the "std.fs" interface well - e.g.cwd().getRelativePath(...)could give you a RelativePath for use with the POSIX-stylestd.osfunctions