authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-01-30 23:11:52+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-02-01 15:22:36+02:00
log8d11ade6a769fe498ed20cdb4f80c6acf4ca91de
tree3519793f8db0e05d0b9a4239a8b440381fbb1501
parentde9606bed51ed59530b5f9f98609aded14398b98

std: change return type of `wasiCwd`

`fd_t` is not declared on freestanding so returning a `Dir` causes an error.

3 files changed, 8 insertions(+), 8 deletions(-)

lib/std/fs.zig+5-5
...@@ -231,17 +231,17 @@ pub fn renameW(old_dir: Dir, old_sub_path_w: []const u16, new_dir: Dir, new_sub_...@@ -231,17 +231,17 @@ pub fn renameW(old_dir: Dir, old_sub_path_w: []const u16, new_dir: Dir, new_sub_
231/// On POSIX targets, this function is comptime-callable.231/// On POSIX targets, this function is comptime-callable.
232pub fn cwd() Dir {232pub fn cwd() Dir {
233 if (builtin.os.tag == .windows) {233 if (builtin.os.tag == .windows) {
234 return Dir{ .fd = os.windows.peb().ProcessParameters.CurrentDirectory.Handle };234 return .{ .fd = os.windows.peb().ProcessParameters.CurrentDirectory.Handle };
235 } else if (builtin.os.tag == .wasi) {235 } else if (builtin.os.tag == .wasi) {
236 return std.options.wasiCwd();236 return .{ .fd = std.options.wasiCwd() };
237 } else {237 } else {
238 return Dir{ .fd = os.AT.FDCWD };238 return .{ .fd = os.AT.FDCWD };
239 }239 }
240}240}
241241
242pub fn defaultWasiCwd() Dir {242pub fn defaultWasiCwd() std.os.wasi.fd_t {
243 // Expect the first preopen to be current working directory.243 // Expect the first preopen to be current working directory.
244 return .{ .fd = 3 };244 return 3;
245}245}
246246
247/// Opens a directory at the given path. The directory is a system resource that remains247/// Opens a directory at the given path. The directory is a system resource that remains
lib/std/std.zig+1-1
...@@ -203,7 +203,7 @@ pub const Options = struct {...@@ -203,7 +203,7 @@ pub const Options = struct {
203 enable_segfault_handler: bool = debug.default_enable_segfault_handler,203 enable_segfault_handler: bool = debug.default_enable_segfault_handler,
204204
205 /// Function used to implement `std.fs.cwd` for WASI.205 /// Function used to implement `std.fs.cwd` for WASI.
206 wasiCwd: fn () fs.Dir = fs.defaultWasiCwd,206 wasiCwd: fn () os.wasi.fd_t = fs.defaultWasiCwd,
207207
208 /// The current log level.208 /// The current log level.
209 log_level: log.Level = log.default_level,209 log_level: log.Level = log.default_level,
src/main.zig+2-2
...@@ -45,11 +45,11 @@ pub const std_options = .{...@@ -45,11 +45,11 @@ pub const std_options = .{
45pub const panic = crash_report.panic;45pub const panic = crash_report.panic;
4646
47var wasi_preopens: fs.wasi.Preopens = undefined;47var wasi_preopens: fs.wasi.Preopens = undefined;
48pub fn wasi_cwd() fs.Dir {48pub fn wasi_cwd() std.os.wasi.fd_t {
49 // Expect the first preopen to be current working directory.49 // Expect the first preopen to be current working directory.
50 const cwd_fd: std.os.fd_t = 3;50 const cwd_fd: std.os.fd_t = 3;
51 assert(mem.eql(u8, wasi_preopens.names[cwd_fd], "."));51 assert(mem.eql(u8, wasi_preopens.names[cwd_fd], "."));
52 return .{ .fd = cwd_fd };52 return cwd_fd;
53}53}
5454
55pub fn getWasiPreopen(name: []const u8) Compilation.Directory {55pub fn getWasiPreopen(name: []const u8) Compilation.Directory {