-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Closed
Copy link
Labels
contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.os-wasistandard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Milestone
Description
Here's how they do it in WASI libc:
- Add basic emulation of getcwd/chdir WebAssembly/wasi-libc#214
- AT_FDCWD support. WebAssembly/wasi-libc#230
In the Zig standard library, what we currently do for WASI is this:
Lines 2242 to 2245 in abbcf40
} else if (builtin.os.tag == .wasi and !builtin.link_libc) { | |
@compileError("WASI doesn't have a concept of cwd(); use std.fs.wasi.PreopenList to get available Dir handles instead"); | |
} else { | |
return Dir{ .fd = os.AT.FDCWD }; |
Notice that for WASI libc however they have an "emulated FD_ATCWD". It looks like it just treats /
as the cwd.
Instead of erroring out, let's follow this convention by returning fd = std.os.wasi.AT.FDCWD
which matches the WASI libc convention of -2
.
Then we have to check for FD_ATCWD at every std.os function (see similar code in the WASI libc PR linked above). For example:
int fstatat(int dirfd, const char *__restrict pathname, struct stat *__restrict statbuf, int flags) {
if (dirfd == AT_FDCWD || pathname[0] == '/') {
return __wasilibc_stat(pathname, statbuf, flags);
}
return __wasilibc_nocwd_fstatat(dirfd, pathname, statbuf, flags);
}
This is a prerequisite for #10716.
Metadata
Metadata
Assignees
Labels
contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.os-wasistandard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.