authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-17 11:46:02+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-17 11:52:30+03:00
logfcaeca5b0acc4cc5930756301f56f7b56dc0a020
treeb08a4534d3fde17f8087b3e968c1286ea63aaae5
parenta39c51c6a44fd6d8e3a5e82bcfd2db61c8972ea6

std.fs: add `Iterable` versions of `openDirAbsolute*`

Follow up to 262f4c7b3a850594a75ec154db2ba8d5f9f517ab

1 files changed, 28 insertions(+), 1 deletions(-)

lib/std/fs.zig+28-1
......@@ -1624,7 +1624,7 @@ pub const Dir = struct {
16241624 pub fn openDirZ(self: Dir, sub_path_c: [*:0]const u8, args: OpenDirOptions, iterable: bool) OpenError!Dir {
16251625 if (builtin.os.tag == .windows) {
16261626 const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c);
1627 return self.openDirW(sub_path_w.span().ptr, args);
1627 return self.openDirW(sub_path_w.span().ptr, args, iterable);
16281628 }
16291629 const symlink_flags: u32 = if (args.no_follow) os.O.NOFOLLOW else 0x0;
16301630 if (!iterable) {
......@@ -2370,6 +2370,33 @@ pub fn openDirAbsoluteW(absolute_path_c: [*:0]const u16, flags: Dir.OpenDirOptio
23702370 return cwd().openDirW(absolute_path_c, flags);
23712371}
23722372
2373/// Opens a directory at the given path. The directory is a system resource that remains
2374/// open until `close` is called on the result.
2375/// See `openIterableDirAbsoluteZ` for a function that accepts a null-terminated path.
2376///
2377/// Asserts that the path parameter has no null bytes.
2378pub fn openIterableDirAbsolute(absolute_path: []const u8, flags: Dir.OpenDirOptions) File.OpenError!IterableDir {
2379 assert(path.isAbsolute(absolute_path));
2380 return cwd().openIterableDir(absolute_path, flags);
2381}
2382
2383/// Same as `openIterableDirAbsolute` but the path parameter is null-terminated.
2384pub fn openIterableDirAbsoluteZ(absolute_path_c: [*:0]const u8, flags: Dir.OpenDirOptions) File.OpenError!IterableDir {
2385 assert(path.isAbsoluteZ(absolute_path_c));
2386 return IterableDir{ .dir = try cwd().openDirZ(absolute_path_c, flags, true) };
2387}
2388/// Same as `openIterableDirAbsolute` but the path parameter is null-terminated.
2389pub fn openIterableDirAbsoluteW(absolute_path_c: [*:0]const u16, flags: Dir.OpenDirOptions) File.OpenError!IterableDir {
2390 assert(path.isAbsoluteWindowsW(absolute_path_c));
2391 return IterableDir{ .dir = try cwd().openDirW(absolute_path_c, flags, true) };
2392}
2393
2394comptime {
2395 _ = openIterableDirAbsolute;
2396 _ = openIterableDirAbsoluteZ;
2397 _ = openIterableDirAbsoluteW;
2398}
2399
23732400/// Opens a file for reading or writing, without attempting to create a new file, based on an absolute path.
23742401/// Call `File.close` to release the resource.
23752402/// Asserts that the path is absolute. See `Dir.openFile` for a function that