diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-10-19 20:42:43 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-10-29 06:20:50 -0700 |
| commit | ed7747e90fcf6c26860788d4b0aafdaa07c8e068 (patch) | |
| tree | 92ba41a593d375ce1099bcd6f27d98e7d324c58f /lib/std | |
| parent | 10b1eef2d3901d17cf8810689a9e1eaf6d7901d9 (diff) | |
| download | zig-ed7747e90fcf6c26860788d4b0aafdaa07c8e068.tar.gz zig-ed7747e90fcf6c26860788d4b0aafdaa07c8e068.zip | |
std.Io.Threaded: add dirMake for Windows
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/Io/Threaded.zig | 26 | ||||
| -rw-r--r-- | lib/std/posix.zig | 27 |
2 files changed, 27 insertions, 26 deletions
diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index 18e6e72563..d851ce30fe 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -164,7 +164,7 @@ pub fn io(t: *Threaded) Io { .conditionWake = conditionWake, .dirMake = switch (builtin.os.tag) { - .windows => @panic("TODO"), + .windows => dirMakeWindows, .wasi => dirMakeWasi, else => dirMakePosix, }, @@ -968,6 +968,28 @@ fn dirMakeWasi(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, mode: I } } +fn dirMakeWindows(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, mode: Io.Dir.Mode) Io.Dir.MakeError!void { + const t: *Threaded = @ptrCast(@alignCast(userdata)); + try t.checkCancel(); + + const sub_path_w = try windows.sliceToPrefixedFileW(dir.handle, sub_path); + _ = mode; + const sub_dir_handle = windows.OpenFile(sub_path_w.span(), .{ + .dir = dir.handle, + .access_mask = windows.GENERIC_READ | windows.SYNCHRONIZE, + .creation = windows.FILE_CREATE, + .filter = .dir_only, + }) catch |err| switch (err) { + error.IsDir => return error.Unexpected, + error.PipeBusy => return error.Unexpected, + error.NoDevice => return error.Unexpected, + error.WouldBlock => return error.Unexpected, + error.AntivirusInterference => return error.Unexpected, + else => |e| return e, + }; + windows.CloseHandle(sub_dir_handle); +} + fn dirStat(userdata: ?*anyopaque, dir: Io.Dir) Io.Dir.StatError!Io.Dir.Stat { const t: *Threaded = @ptrCast(@alignCast(userdata)); try t.checkCancel(); @@ -3164,7 +3186,7 @@ fn netInterfaceNameResolve( if (native_os == .windows) { try t.checkCancel(); - const index = std.os.windows.ws2_32.if_nametoindex(&name.bytes); + const index = windows.ws2_32.if_nametoindex(&name.bytes); if (index == 0) return error.InterfaceNotFound; return .{ .index = index }; } diff --git a/lib/std/posix.zig b/lib/std/posix.zig index 02dc6c6087..fd4958c5e8 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -2691,8 +2691,7 @@ pub fn renameatW( /// On other platforms, `sub_dir_path` is an opaque sequence of bytes with no particular encoding. pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: mode_t) MakeDirError!void { if (native_os == .windows) { - const sub_dir_path_w = try windows.sliceToPrefixedFileW(dir_fd, sub_dir_path); - return mkdiratW(dir_fd, sub_dir_path_w.span(), mode); + @compileError("use std.Io instead"); } else if (native_os == .wasi and !builtin.link_libc) { @compileError("use std.Io instead"); } else { @@ -2704,10 +2703,9 @@ pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: mode_t) MakeDirErro /// Same as `mkdirat` except the parameters are null-terminated. pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: mode_t) MakeDirError!void { if (native_os == .windows) { - const sub_dir_path_w = try windows.cStrToPrefixedFileW(dir_fd, sub_dir_path); - return mkdiratW(dir_fd, sub_dir_path_w.span(), mode); + @compileError("use std.Io instead"); } else if (native_os == .wasi and !builtin.link_libc) { - return mkdirat(dir_fd, mem.sliceTo(sub_dir_path, 0), mode); + @compileError("use std.Io instead"); } switch (errno(system.mkdirat(dir_fd, sub_dir_path, mode))) { .SUCCESS => return, @@ -2732,25 +2730,6 @@ pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: mode_t) MakeDir } } -/// Windows-only. Same as `mkdirat` except the parameter WTF16 LE encoded. -pub fn mkdiratW(dir_fd: fd_t, sub_path_w: []const u16, mode: mode_t) MakeDirError!void { - _ = mode; - const sub_dir_handle = windows.OpenFile(sub_path_w, .{ - .dir = dir_fd, - .access_mask = windows.GENERIC_READ | windows.SYNCHRONIZE, - .creation = windows.FILE_CREATE, - .filter = .dir_only, - }) catch |err| switch (err) { - error.IsDir => return error.Unexpected, - error.PipeBusy => return error.Unexpected, - error.NoDevice => return error.Unexpected, - error.WouldBlock => return error.Unexpected, - error.AntivirusInterference => return error.Unexpected, - else => |e| return e, - }; - windows.CloseHandle(sub_dir_handle); -} - pub const MakeDirError = std.Io.Dir.MakeError; /// Create a directory. |
