commit 8d11ade6a769fe498ed20cdb4f80c6acf4ca91de (tree)
parent de9606bed51ed59530b5f9f98609aded14398b98
Author: Veikka Tuominen <git@vexu.eu>
Date: Tue, 30 Jan 2024 23:11:52 +0200
std: change return type of `wasiCwd`
`fd_t` is not declared on freestanding so returning a `Dir` causes an error.
Diffstat:
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/lib/std/fs.zig b/lib/std/fs.zig
@@ -231,17 +231,17 @@ pub fn renameW(old_dir: Dir, old_sub_path_w: []const u16, new_dir: Dir, new_sub_
/// On POSIX targets, this function is comptime-callable.
pub fn cwd() Dir {
if (builtin.os.tag == .windows) {
- return Dir{ .fd = os.windows.peb().ProcessParameters.CurrentDirectory.Handle };
+ return .{ .fd = os.windows.peb().ProcessParameters.CurrentDirectory.Handle };
} else if (builtin.os.tag == .wasi) {
- return std.options.wasiCwd();
+ return .{ .fd = std.options.wasiCwd() };
} else {
- return Dir{ .fd = os.AT.FDCWD };
+ return .{ .fd = os.AT.FDCWD };
}
}
-pub fn defaultWasiCwd() Dir {
+pub fn defaultWasiCwd() std.os.wasi.fd_t {
// Expect the first preopen to be current working directory.
- return .{ .fd = 3 };
+ return 3;
}
/// Opens a directory at the given path. The directory is a system resource that remains
diff --git a/lib/std/std.zig b/lib/std/std.zig
@@ -203,7 +203,7 @@ pub const Options = struct {
enable_segfault_handler: bool = debug.default_enable_segfault_handler,
/// Function used to implement `std.fs.cwd` for WASI.
- wasiCwd: fn () fs.Dir = fs.defaultWasiCwd,
+ wasiCwd: fn () os.wasi.fd_t = fs.defaultWasiCwd,
/// The current log level.
log_level: log.Level = log.default_level,
diff --git a/src/main.zig b/src/main.zig
@@ -45,11 +45,11 @@ pub const std_options = .{
pub const panic = crash_report.panic;
var wasi_preopens: fs.wasi.Preopens = undefined;
-pub fn wasi_cwd() fs.Dir {
+pub fn wasi_cwd() std.os.wasi.fd_t {
// Expect the first preopen to be current working directory.
const cwd_fd: std.os.fd_t = 3;
assert(mem.eql(u8, wasi_preopens.names[cwd_fd], "."));
- return .{ .fd = cwd_fd };
+ return cwd_fd;
}
pub fn getWasiPreopen(name: []const u8) Compilation.Directory {