diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-07-17 11:46:02 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-07-17 11:52:30 +0300 |
| commit | fcaeca5b0acc4cc5930756301f56f7b56dc0a020 (patch) | |
| tree | b08a4534d3fde17f8087b3e968c1286ea63aaae5 /lib/std | |
| parent | a39c51c6a44fd6d8e3a5e82bcfd2db61c8972ea6 (diff) | |
| download | zig-fcaeca5b0acc4cc5930756301f56f7b56dc0a020.tar.gz zig-fcaeca5b0acc4cc5930756301f56f7b56dc0a020.zip | |
std.fs: add `Iterable` versions of `openDirAbsolute*`
Follow up to 262f4c7b3a850594a75ec154db2ba8d5f9f517ab
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/fs.zig | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 9e79d29469..1886c9c433 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -1624,7 +1624,7 @@ pub const Dir = struct { pub fn openDirZ(self: Dir, sub_path_c: [*:0]const u8, args: OpenDirOptions, iterable: bool) OpenError!Dir { if (builtin.os.tag == .windows) { const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c); - return self.openDirW(sub_path_w.span().ptr, args); + return self.openDirW(sub_path_w.span().ptr, args, iterable); } const symlink_flags: u32 = if (args.no_follow) os.O.NOFOLLOW else 0x0; if (!iterable) { @@ -2370,6 +2370,33 @@ pub fn openDirAbsoluteW(absolute_path_c: [*:0]const u16, flags: Dir.OpenDirOptio return cwd().openDirW(absolute_path_c, flags); } +/// Opens a directory at the given path. The directory is a system resource that remains +/// open until `close` is called on the result. +/// See `openIterableDirAbsoluteZ` for a function that accepts a null-terminated path. +/// +/// Asserts that the path parameter has no null bytes. +pub fn openIterableDirAbsolute(absolute_path: []const u8, flags: Dir.OpenDirOptions) File.OpenError!IterableDir { + assert(path.isAbsolute(absolute_path)); + return cwd().openIterableDir(absolute_path, flags); +} + +/// Same as `openIterableDirAbsolute` but the path parameter is null-terminated. +pub fn openIterableDirAbsoluteZ(absolute_path_c: [*:0]const u8, flags: Dir.OpenDirOptions) File.OpenError!IterableDir { + assert(path.isAbsoluteZ(absolute_path_c)); + return IterableDir{ .dir = try cwd().openDirZ(absolute_path_c, flags, true) }; +} +/// Same as `openIterableDirAbsolute` but the path parameter is null-terminated. +pub fn openIterableDirAbsoluteW(absolute_path_c: [*:0]const u16, flags: Dir.OpenDirOptions) File.OpenError!IterableDir { + assert(path.isAbsoluteWindowsW(absolute_path_c)); + return IterableDir{ .dir = try cwd().openDirW(absolute_path_c, flags, true) }; +} + +comptime { + _ = openIterableDirAbsolute; + _ = openIterableDirAbsoluteZ; + _ = openIterableDirAbsoluteW; +} + /// Opens a file for reading or writing, without attempting to create a new file, based on an absolute path. /// Call `File.close` to release the resource. /// Asserts that the path is absolute. See `Dir.openFile` for a function that |
