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 {...@@ -164,7 +164,7 @@ pub fn io(t: *Threaded) Io {
164 .conditionWake = conditionWake,164 .conditionWake = conditionWake,
165165
166 .dirMake = switch (builtin.os.tag) {166 .dirMake = switch (builtin.os.tag) {
167 .windows => @panic("TODO"),167 .windows => dirMakeWindows,
168 .wasi => dirMakeWasi,168 .wasi => dirMakeWasi,
169 else => dirMakePosix,169 else => dirMakePosix,
170 },170 },
...@@ -968,6 +968,28 @@ fn dirMakeWasi(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, mode: I...@@ -968,6 +968,28 @@ fn dirMakeWasi(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, mode: I
968 }968 }
969}969}
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
971fn dirStat(userdata: ?*anyopaque, dir: Io.Dir) Io.Dir.StatError!Io.Dir.Stat {993fn dirStat(userdata: ?*anyopaque, dir: Io.Dir) Io.Dir.StatError!Io.Dir.Stat {
972 const t: *Threaded = @ptrCast(@alignCast(userdata));994 const t: *Threaded = @ptrCast(@alignCast(userdata));
973 try t.checkCancel();995 try t.checkCancel();
...@@ -3164,7 +3186,7 @@ fn netInterfaceNameResolve(...@@ -3164,7 +3186,7 @@ fn netInterfaceNameResolve(
31643186
3165 if (native_os == .windows) {3187 if (native_os == .windows) {
3166 try t.checkCancel();3188 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);
3168 if (index == 0) return error.InterfaceNotFound;3190 if (index == 0) return error.InterfaceNotFound;
3169 return .{ .index = index };3191 return .{ .index = index };
3170 }3192 }
lib/std/posix.zig+3-24
...@@ -2691,8 +2691,7 @@ pub fn renameatW(...@@ -2691,8 +2691,7 @@ pub fn renameatW(
2691/// On other platforms, `sub_dir_path` is an opaque sequence of bytes with no particular encoding.2691/// On other platforms, `sub_dir_path` is an opaque sequence of bytes with no particular encoding.
2692pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: mode_t) MakeDirError!void {2692pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: mode_t) MakeDirError!void {
2693 if (native_os == .windows) {2693 if (native_os == .windows) {
2694 const sub_dir_path_w = try windows.sliceToPrefixedFileW(dir_fd, sub_dir_path);2694 @compileError("use std.Io instead");
2695 return mkdiratW(dir_fd, sub_dir_path_w.span(), mode);
2696 } else if (native_os == .wasi and !builtin.link_libc) {2695 } else if (native_os == .wasi and !builtin.link_libc) {
2697 @compileError("use std.Io instead");2696 @compileError("use std.Io instead");
2698 } else {2697 } else {
...@@ -2704,10 +2703,9 @@ pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: mode_t) MakeDirErro...@@ -2704,10 +2703,9 @@ pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: mode_t) MakeDirErro
2704/// Same as `mkdirat` except the parameters are null-terminated.2703/// Same as `mkdirat` except the parameters are null-terminated.
2705pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: mode_t) MakeDirError!void {2704pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: mode_t) MakeDirError!void {
2706 if (native_os == .windows) {2705 if (native_os == .windows) {
2707 const sub_dir_path_w = try windows.cStrToPrefixedFileW(dir_fd, sub_dir_path);2706 @compileError("use std.Io instead");
2708 return mkdiratW(dir_fd, sub_dir_path_w.span(), mode);
2709 } else if (native_os == .wasi and !builtin.link_libc) {2707 } 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");
2711 }2709 }
2712 switch (errno(system.mkdirat(dir_fd, sub_dir_path, mode))) {2710 switch (errno(system.mkdirat(dir_fd, sub_dir_path, mode))) {
2713 .SUCCESS => return,2711 .SUCCESS => return,
...@@ -2732,25 +2730,6 @@ pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: mode_t) MakeDir...@@ -2732,25 +2730,6 @@ pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: mode_t) MakeDir
2732 }2730 }
2733}2731}
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
2754pub const MakeDirError = std.Io.Dir.MakeError;2733pub const MakeDirError = std.Io.Dir.MakeError;
27552734
2756/// Create a directory.2735/// Create a directory.