authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-19 20:42:43-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:50-07:00
loged7747e90fcf6c26860788d4b0aafdaa07c8e068
tree92ba41a593d375ce1099bcd6f27d98e7d324c58f
parent10b1eef2d3901d17cf8810689a9e1eaf6d7901d9

std.Io.Threaded: add dirMake for Windows


2 files changed, 27 insertions(+), 26 deletions(-)

lib/std/Io/Threaded.zig+24-2
......@@ -164,7 +164,7 @@ pub fn io(t: *Threaded) Io {
164164 .conditionWake = conditionWake,
165165
166166 .dirMake = switch (builtin.os.tag) {
167 .windows => @panic("TODO"),
167 .windows => dirMakeWindows,
168168 .wasi => dirMakeWasi,
169169 else => dirMakePosix,
170170 },
......@@ -968,6 +968,28 @@ fn dirMakeWasi(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, mode: I
968968 }
969969}
970970
971fn dirMakeWindows(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, mode: Io.Dir.Mode) Io.Dir.MakeError!void {
972 const t: *Threaded = @ptrCast(@alignCast(userdata));
973 try t.checkCancel();
974
975 const sub_path_w = try windows.sliceToPrefixedFileW(dir.handle, sub_path);
976 _ = mode;
977 const sub_dir_handle = windows.OpenFile(sub_path_w.span(), .{
978 .dir = dir.handle,
979 .access_mask = windows.GENERIC_READ | windows.SYNCHRONIZE,
980 .creation = windows.FILE_CREATE,
981 .filter = .dir_only,
982 }) catch |err| switch (err) {
983 error.IsDir => return error.Unexpected,
984 error.PipeBusy => return error.Unexpected,
985 error.NoDevice => return error.Unexpected,
986 error.WouldBlock => return error.Unexpected,
987 error.AntivirusInterference => return error.Unexpected,
988 else => |e| return e,
989 };
990 windows.CloseHandle(sub_dir_handle);
991}
992
971993fn dirStat(userdata: ?*anyopaque, dir: Io.Dir) Io.Dir.StatError!Io.Dir.Stat {
972994 const t: *Threaded = @ptrCast(@alignCast(userdata));
973995 try t.checkCancel();
......@@ -3164,7 +3186,7 @@ fn netInterfaceNameResolve(
31643186
31653187 if (native_os == .windows) {
31663188 try t.checkCancel();
3167 const index = std.os.windows.ws2_32.if_nametoindex(&name.bytes);
3189 const index = windows.ws2_32.if_nametoindex(&name.bytes);
31683190 if (index == 0) return error.InterfaceNotFound;
31693191 return .{ .index = index };
31703192 }
lib/std/posix.zig+3-24
......@@ -2691,8 +2691,7 @@ pub fn renameatW(
26912691/// On other platforms, `sub_dir_path` is an opaque sequence of bytes with no particular encoding.
26922692pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: mode_t) MakeDirError!void {
26932693 if (native_os == .windows) {
2694 const sub_dir_path_w = try windows.sliceToPrefixedFileW(dir_fd, sub_dir_path);
2695 return mkdiratW(dir_fd, sub_dir_path_w.span(), mode);
2694 @compileError("use std.Io instead");
26962695 } else if (native_os == .wasi and !builtin.link_libc) {
26972696 @compileError("use std.Io instead");
26982697 } else {
......@@ -2704,10 +2703,9 @@ pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: mode_t) MakeDirErro
27042703/// Same as `mkdirat` except the parameters are null-terminated.
27052704pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: mode_t) MakeDirError!void {
27062705 if (native_os == .windows) {
2707 const sub_dir_path_w = try windows.cStrToPrefixedFileW(dir_fd, sub_dir_path);
2708 return mkdiratW(dir_fd, sub_dir_path_w.span(), mode);
2706 @compileError("use std.Io instead");
27092707 } else if (native_os == .wasi and !builtin.link_libc) {
2710 return mkdirat(dir_fd, mem.sliceTo(sub_dir_path, 0), mode);
2708 @compileError("use std.Io instead");
27112709 }
27122710 switch (errno(system.mkdirat(dir_fd, sub_dir_path, mode))) {
27132711 .SUCCESS => return,
......@@ -2732,25 +2730,6 @@ pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: mode_t) MakeDir
27322730 }
27332731}
27342732
2735/// Windows-only. Same as `mkdirat` except the parameter WTF16 LE encoded.
2736pub fn mkdiratW(dir_fd: fd_t, sub_path_w: []const u16, mode: mode_t) MakeDirError!void {
2737 _ = mode;
2738 const sub_dir_handle = windows.OpenFile(sub_path_w, .{
2739 .dir = dir_fd,
2740 .access_mask = windows.GENERIC_READ | windows.SYNCHRONIZE,
2741 .creation = windows.FILE_CREATE,
2742 .filter = .dir_only,
2743 }) catch |err| switch (err) {
2744 error.IsDir => return error.Unexpected,
2745 error.PipeBusy => return error.Unexpected,
2746 error.NoDevice => return error.Unexpected,
2747 error.WouldBlock => return error.Unexpected,
2748 error.AntivirusInterference => return error.Unexpected,
2749 else => |e| return e,
2750 };
2751 windows.CloseHandle(sub_dir_handle);
2752}
2753
27542733pub const MakeDirError = std.Io.Dir.MakeError;
27552734
27562735/// Create a directory.