diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-10-19 22:17:45 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-10-29 06:20:50 -0700 |
| commit | 6d1b2c7f64fd1a1c671f357cff96b3dd39612857 (patch) | |
| tree | 996e692c2b132f48827de477da5a8777bd8ee1fb /lib/std/Io/Dir.zig | |
| parent | 1c67607397be4efa962d64a1d80b7fd91fe161eb (diff) | |
| download | zig-6d1b2c7f64fd1a1c671f357cff96b3dd39612857.tar.gz zig-6d1b2c7f64fd1a1c671f357cff96b3dd39612857.zip | |
std.Io: introduce openSelfExe
Diffstat (limited to 'lib/std/Io/Dir.zig')
| -rw-r--r-- | lib/std/Io/Dir.zig | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/std/Io/Dir.zig b/lib/std/Io/Dir.zig index ab8f75e541..7336ab24af 100644 --- a/lib/std/Io/Dir.zig +++ b/lib/std/Io/Dir.zig @@ -1,5 +1,8 @@ const Dir = @This(); +const builtin = @import("builtin"); +const native_os = builtin.os.tag; + const std = @import("../std.zig"); const Io = std.Io; const File = Io.File; @@ -9,8 +12,20 @@ handle: Handle, pub const Mode = Io.File.Mode; pub const default_mode: Mode = 0o755; +/// Returns a handle to the current working directory. +/// +/// It is not opened with iteration capability. Iterating over the result is +/// illegal behavior. +/// +/// Closing the returned `Dir` is checked illegal behavior. +/// +/// On POSIX targets, this function is comptime-callable. pub fn cwd() Dir { - return .{ .handle = std.fs.cwd().fd }; + return switch (native_os) { + .windows => .{ .handle = std.os.windows.peb().ProcessParameters.CurrentDirectory.Handle }, + .wasi => .{ .handle = std.options.wasiCwd() }, + else => .{ .handle = std.posix.AT.FDCWD }, + }; } pub const Handle = std.posix.fd_t; |
