| ... | @@ -817,8 +817,13 @@ pub const Dir = struct { | ... | @@ -817,8 +817,13 @@ pub const Dir = struct { |
| 817 | | 817 | |
| 818 | /// Same as `openDirTraverse` except the parameter is null-terminated. | 818 | /// Same as `openDirTraverse` except the parameter is null-terminated. |
| 819 | pub fn openDirTraverseC(self: Dir, sub_path_c: [*:0]const u8) OpenError!Dir { | 819 | pub fn openDirTraverseC(self: Dir, sub_path_c: [*:0]const u8) OpenError!Dir { |
| 820 | // TODO: use O_PATH where supported | 820 | if (builtin.os == .windows) { |
| 821 | return self.openDirListC(sub_path_c); | 821 | const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c); |
| | 822 | return self.openDirTraverseW(&sub_path_w); |
| | 823 | } else { |
| | 824 | const O_PATH = if (@hasDecl(os, "O_PATH")) os.O_PATH else 0; |
| | 825 | return self.openDirFlagsC(sub_path_c, os.O_RDONLY | os.O_DIRECTORY | os.O_CLOEXEC | O_PATH); |
| | 826 | } |
| 822 | } | 827 | } |
| 823 | | 828 | |
| 824 | /// Same as `openDirList` except the parameter is null-terminated. | 829 | /// Same as `openDirList` except the parameter is null-terminated. |
| ... | @@ -826,9 +831,12 @@ pub const Dir = struct { | ... | @@ -826,9 +831,12 @@ pub const Dir = struct { |
| 826 | if (builtin.os == .windows) { | 831 | if (builtin.os == .windows) { |
| 827 | const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c); | 832 | const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c); |
| 828 | return self.openDirListW(&sub_path_w); | 833 | return self.openDirListW(&sub_path_w); |
| | 834 | } else { |
| | 835 | return self.openDirFlagsC(sub_path_c, os.O_RDONLY | os.O_DIRECTORY | os.O_CLOEXEC); |
| 829 | } | 836 | } |
| | 837 | } |
| 830 | | 838 | |
| 831 | const flags = os.O_RDONLY | os.O_DIRECTORY | os.O_CLOEXEC; | 839 | fn openDirFlagsC(self: Dir, sub_path_c: [*]const u8, flags: u32) OpenError!Dir { |
| 832 | const fd = os.openatC(self.fd, sub_path_c, flags, 0) catch |err| switch (err) { | 840 | const fd = os.openatC(self.fd, sub_path_c, flags, 0) catch |err| switch (err) { |
| 833 | error.FileTooBig => unreachable, // can't happen for directories | 841 | error.FileTooBig => unreachable, // can't happen for directories |
| 834 | error.IsDir => unreachable, // we're providing O_DIRECTORY | 842 | error.IsDir => unreachable, // we're providing O_DIRECTORY |