authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-19 12:55:00-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:11-08:00
log405db921dc0a053d7bebca6195c5a0031a5b187b
tree1988327af5b062c5988291c0d9667fab36f5c9d0
parent1381f9f612a5e03895615ade253411d86bce31a4

std: fix compilation targeting WASI


5 files changed, 81 insertions(+), 33 deletions(-)

lib/std/Io/File.zig+1-1
...@@ -429,7 +429,7 @@ pub const Permissions = std.options.FilePermissions orelse if (is_windows) enum(...@@ -429,7 +429,7 @@ pub const Permissions = std.options.FilePermissions orelse if (is_windows) enum(
429 executable_file = 0o777,429 executable_file = 0o777,
430 _,430 _,
431431
432 pub const has_executable_bit = true;432 pub const has_executable_bit = native_os != .wasi;
433433
434 pub fn toMode(self: @This()) std.posix.mode_t {434 pub fn toMode(self: @This()) std.posix.mode_t {
435 return @intFromEnum(self);435 return @intFromEnum(self);
lib/std/Io/Threaded.zig+72-27
...@@ -947,6 +947,16 @@ const have_fchmodat2 = native_os == .linux and...@@ -947,6 +947,16 @@ const have_fchmodat2 = native_os == .linux and
947const have_fchmodat_flags = native_os != .linux or947const have_fchmodat_flags = native_os != .linux or
948 (!builtin.abi.isAndroid() and std.c.versionCheck(.{ .major = 2, .minor = 32, .patch = 0 }));948 (!builtin.abi.isAndroid() and std.c.versionCheck(.{ .major = 2, .minor = 32, .patch = 0 }));
949949
950const have_fchown = switch (native_os) {
951 .wasi, .windows => false,
952 else => true,
953};
954
955const have_fchmod = switch (native_os) {
956 .wasi, .windows => false,
957 else => true,
958};
959
950const openat_sym = if (posix.lfs64_abi) posix.system.openat64 else posix.system.openat;960const openat_sym = if (posix.lfs64_abi) posix.system.openat64 else posix.system.openat;
951const fstat_sym = if (posix.lfs64_abi) posix.system.fstat64 else posix.system.fstat;961const fstat_sym = if (posix.lfs64_abi) posix.system.fstat64 else posix.system.fstat;
952const fstatat_sym = if (posix.lfs64_abi) posix.system.fstatat64 else posix.system.fstatat;962const fstatat_sym = if (posix.lfs64_abi) posix.system.fstatat64 else posix.system.fstatat;
...@@ -1480,6 +1490,7 @@ fn futexWaitUncancelable(userdata: ?*anyopaque, ptr: *const u32, expected: u32)...@@ -1480,6 +1490,7 @@ fn futexWaitUncancelable(userdata: ?*anyopaque, ptr: *const u32, expected: u32)
1480}1490}
14811491
1482fn futexWake(userdata: ?*anyopaque, ptr: *const u32, max_waiters: u32) void {1492fn futexWake(userdata: ?*anyopaque, ptr: *const u32, max_waiters: u32) void {
1493 if (builtin.single_threaded) unreachable; // Nothing to wake up.
1483 const t: *Threaded = @ptrCast(@alignCast(userdata));1494 const t: *Threaded = @ptrCast(@alignCast(userdata));
1484 _ = t;1495 _ = t;
1485 switch (native_os) {1496 switch (native_os) {
...@@ -4190,7 +4201,6 @@ fn dirDeleteFileWasi(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8) Dir....@@ -4190,7 +4201,6 @@ fn dirDeleteFileWasi(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8) Dir.
4190 .NOTDIR => return error.NotDir,4201 .NOTDIR => return error.NotDir,
4191 .NOMEM => return error.SystemResources,4202 .NOMEM => return error.SystemResources,
4192 .ROFS => return error.ReadOnlyFileSystem,4203 .ROFS => return error.ReadOnlyFileSystem,
4193 .NOTEMPTY => return error.DirNotEmpty,
4194 .NOTCAPABLE => return error.AccessDenied,4204 .NOTCAPABLE => return error.AccessDenied,
4195 .ILSEQ => return error.BadPathName,4205 .ILSEQ => return error.BadPathName,
4196 .INVAL => |err| return errnoBug(err), // invalid flags, or pathname has . as last component4206 .INVAL => |err| return errnoBug(err), // invalid flags, or pathname has . as last component
...@@ -4464,7 +4474,6 @@ fn dirDeleteDirWasi(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8) Dir.D...@@ -4464,7 +4474,6 @@ fn dirDeleteDirWasi(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8) Dir.D
4464 .BUSY => return error.FileBusy,4474 .BUSY => return error.FileBusy,
4465 .FAULT => |err| return errnoBug(err),4475 .FAULT => |err| return errnoBug(err),
4466 .IO => return error.FileSystem,4476 .IO => return error.FileSystem,
4467 .ISDIR => return error.IsDir,
4468 .LOOP => return error.SymLinkLoop,4477 .LOOP => return error.SymLinkLoop,
4469 .NAMETOOLONG => return error.NameTooLong,4478 .NAMETOOLONG => return error.NameTooLong,
4470 .NOENT => return error.FileNotFound,4479 .NOENT => return error.FileNotFound,
...@@ -4877,14 +4886,14 @@ fn dirSymLinkWindows(...@@ -4877,14 +4886,14 @@ fn dirSymLinkWindows(
4877 @memcpy(buffer[@sizeOf(SYMLINK_DATA)..][0 .. final_target_path.len * 2], @as([*]const u8, @ptrCast(final_target_path)));4886 @memcpy(buffer[@sizeOf(SYMLINK_DATA)..][0 .. final_target_path.len * 2], @as([*]const u8, @ptrCast(final_target_path)));
4878 const paths_start = @sizeOf(SYMLINK_DATA) + final_target_path.len * 2;4887 const paths_start = @sizeOf(SYMLINK_DATA) + final_target_path.len * 2;
4879 @memcpy(buffer[paths_start..][0 .. final_target_path.len * 2], @as([*]const u8, @ptrCast(final_target_path)));4888 @memcpy(buffer[paths_start..][0 .. final_target_path.len * 2], @as([*]const u8, @ptrCast(final_target_path)));
4880 _ = w.DeviceIoControl(symlink_handle, w.FSCTL.SET_REPARSE_POINT, .{ .in = buffer[0..buf_len] }) catch |err| switch (err) {4889 const rc = w.DeviceIoControl(symlink_handle, w.FSCTL.SET_REPARSE_POINT, .{ .in = buffer[0..buf_len] });
4881 error.PipeClosing => unreachable,4890 switch (rc) {
4882 error.PipeAlreadyConnected => unreachable,4891 .SUCCESS => {},
4883 error.PipeAlreadyListening => unreachable,4892 .PRIVILEGE_NOT_HELD => return error.PermissionDenied,
4884 error.Pending => unreachable,4893 .ACCESS_DENIED => return error.AccessDenied,
4885 error.UnrecognizedVolume => unreachable,4894 .INVALID_DEVICE_REQUEST => return error.FileSystem,
4886 else => |e| return e,4895 else => return windows.unexpectedStatus(rc),
4887 };4896 }
4888}4897}
48894898
4890fn dirSymLinkWasi(4899fn dirSymLinkWasi(
...@@ -4894,7 +4903,7 @@ fn dirSymLinkWasi(...@@ -4894,7 +4903,7 @@ fn dirSymLinkWasi(
4894 sym_link_path: []const u8,4903 sym_link_path: []const u8,
4895 flags: Dir.SymLinkFlags,4904 flags: Dir.SymLinkFlags,
4896) Dir.SymLinkError!void {4905) Dir.SymLinkError!void {
4897 if (builtin.link_libc) return dirSymLinkPosix(dir, target_path, sym_link_path, flags);4906 if (builtin.link_libc) return dirSymLinkPosix(userdata, dir, target_path, sym_link_path, flags);
48984907
4899 const t: *Threaded = @ptrCast(@alignCast(userdata));4908 const t: *Threaded = @ptrCast(@alignCast(userdata));
4900 const current_thread = Thread.getCurrent(t);4909 const current_thread = Thread.getCurrent(t);
...@@ -5021,7 +5030,7 @@ fn dirReadLinkWasi(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, buffer...@@ -5021,7 +5030,7 @@ fn dirReadLinkWasi(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, buffer
5021 switch (std.os.wasi.path_readlink(dir.handle, sub_path.ptr, sub_path.len, buffer.ptr, buffer.len, &n)) {5030 switch (std.os.wasi.path_readlink(dir.handle, sub_path.ptr, sub_path.len, buffer.ptr, buffer.len, &n)) {
5022 .SUCCESS => {5031 .SUCCESS => {
5023 current_thread.endSyscall();5032 current_thread.endSyscall();
5024 return buffer[0..n];5033 return n;
5025 },5034 },
5026 .CANCELED => return current_thread.endSyscallCanceled(),5035 .CANCELED => return current_thread.endSyscallCanceled(),
5027 .INTR => {5036 .INTR => {
...@@ -5104,6 +5113,7 @@ fn dirSetPermissionsWindows(userdata: ?*anyopaque, dir: Dir, permissions: Dir.Pe...@@ -5104,6 +5113,7 @@ fn dirSetPermissionsWindows(userdata: ?*anyopaque, dir: Dir, permissions: Dir.Pe
5104}5113}
51055114
5106fn dirSetPermissionsPosix(userdata: ?*anyopaque, dir: Dir, permissions: Dir.Permissions) Dir.SetPermissionsError!void {5115fn dirSetPermissionsPosix(userdata: ?*anyopaque, dir: Dir, permissions: Dir.Permissions) Dir.SetPermissionsError!void {
5116 if (@sizeOf(Dir.Permissions) == 0) return;
5107 const t: *Threaded = @ptrCast(@alignCast(userdata));5117 const t: *Threaded = @ptrCast(@alignCast(userdata));
5108 const current_thread = Thread.getCurrent(t);5118 const current_thread = Thread.getCurrent(t);
5109 return setPermissionsPosix(current_thread, dir.handle, permissions.toMode());5119 return setPermissionsPosix(current_thread, dir.handle, permissions.toMode());
...@@ -5116,7 +5126,7 @@ fn dirSetFilePermissions(...@@ -5116,7 +5126,7 @@ fn dirSetFilePermissions(
5116 permissions: Dir.Permissions,5126 permissions: Dir.Permissions,
5117 options: Dir.SetFilePermissionsOptions,5127 options: Dir.SetFilePermissionsOptions,
5118) Dir.SetFilePermissionsError!void {5128) Dir.SetFilePermissionsError!void {
5119 if (!Dir.Permissions.has_executable_bit) return error.Unexpected;5129 if (@sizeOf(Dir.Permissions) == 0) return;
5120 if (is_windows) @panic("TODO");5130 if (is_windows) @panic("TODO");
5121 const t: *Threaded = @ptrCast(@alignCast(userdata));5131 const t: *Threaded = @ptrCast(@alignCast(userdata));
5122 const current_thread = Thread.getCurrent(t);5132 const current_thread = Thread.getCurrent(t);
...@@ -5250,14 +5260,16 @@ fn dirSetOwnerUnsupported(userdata: ?*anyopaque, dir: Dir, owner: ?File.Uid, gro...@@ -5250,14 +5260,16 @@ fn dirSetOwnerUnsupported(userdata: ?*anyopaque, dir: Dir, owner: ?File.Uid, gro
5250}5260}
52515261
5252fn dirSetOwnerPosix(userdata: ?*anyopaque, dir: Dir, owner: ?File.Uid, group: ?File.Gid) Dir.SetOwnerError!void {5262fn dirSetOwnerPosix(userdata: ?*anyopaque, dir: Dir, owner: ?File.Uid, group: ?File.Gid) Dir.SetOwnerError!void {
5263 if (!have_fchown) return error.Unexpected; // Unsupported OS, don't call this function.
5253 const t: *Threaded = @ptrCast(@alignCast(userdata));5264 const t: *Threaded = @ptrCast(@alignCast(userdata));
5254 const current_thread = Thread.getCurrent(t);5265 const current_thread = Thread.getCurrent(t);
5255 const uid = owner orelse ~@as(posix.uid_t, 0);5266 const uid = owner orelse ~@as(posix.uid_t, 0);
5256 const gid = group orelse ~@as(posix.gid_t, 0);5267 const gid = group orelse ~@as(posix.gid_t, 0);
5257 return setOwnerPosix(current_thread, dir.handle, uid, gid);5268 return posixFchown(current_thread, dir.handle, uid, gid);
5258}5269}
52595270
5260fn setOwnerPosix(current_thread: *Thread, fd: posix.fd_t, uid: posix.uid_t, gid: posix.gid_t) File.SetOwnerError!void {5271fn posixFchown(current_thread: *Thread, fd: posix.fd_t, uid: posix.uid_t, gid: posix.gid_t) File.SetOwnerError!void {
5272 comptime assert(have_fchown);
5261 try current_thread.beginSyscall();5273 try current_thread.beginSyscall();
5262 while (true) {5274 while (true) {
5263 switch (posix.errno(posix.system.fchown(fd, uid, gid))) {5275 switch (posix.errno(posix.system.fchown(fd, uid, gid))) {
...@@ -5296,13 +5308,10 @@ fn dirSetFileOwner(...@@ -5296,13 +5308,10 @@ fn dirSetFileOwner(
5296 group: ?File.Gid,5308 group: ?File.Gid,
5297 options: Dir.SetFileOwnerOptions,5309 options: Dir.SetFileOwnerOptions,
5298) Dir.SetFileOwnerError!void {5310) Dir.SetFileOwnerError!void {
5311 if (!have_fchown) return error.Unexpected; // Unsupported OS, don't call this function.
5299 const t: *Threaded = @ptrCast(@alignCast(userdata));5312 const t: *Threaded = @ptrCast(@alignCast(userdata));
5300 const current_thread = Thread.getCurrent(t);5313 const current_thread = Thread.getCurrent(t);
53015314
5302 if (is_windows) {
5303 @panic("TODO");
5304 }
5305
5306 var path_buffer: [posix.PATH_MAX]u8 = undefined;5315 var path_buffer: [posix.PATH_MAX]u8 = undefined;
5307 const sub_path_posix = try pathToPosix(sub_path, &path_buffer);5316 const sub_path_posix = try pathToPosix(sub_path, &path_buffer);
53085317
...@@ -5317,6 +5326,7 @@ fn dirSetFileOwner(...@@ -5317,6 +5326,7 @@ fn dirSetFileOwner(
53175326
5318const fileSync = switch (native_os) {5327const fileSync = switch (native_os) {
5319 .windows => fileSyncWindows,5328 .windows => fileSyncWindows,
5329 .wasi => fileSyncWasi,
5320 else => fileSyncPosix,5330 else => fileSyncPosix,
5321};5331};
53225332
...@@ -5366,6 +5376,34 @@ fn fileSyncPosix(userdata: ?*anyopaque, file: File) File.SyncError!void {...@@ -5366,6 +5376,34 @@ fn fileSyncPosix(userdata: ?*anyopaque, file: File) File.SyncError!void {
5366 }5376 }
5367}5377}
53685378
5379fn fileSyncWasi(userdata: ?*anyopaque, file: File) File.SyncError!void {
5380 const t: *Threaded = @ptrCast(@alignCast(userdata));
5381 const current_thread = Thread.getCurrent(t);
5382 try current_thread.beginSyscall();
5383 while (true) {
5384 switch (std.os.wasi.fd_sync(file.handle)) {
5385 .SUCCESS => return current_thread.endSyscall(),
5386 .CANCELED => return current_thread.endSyscallCanceled(),
5387 .INTR => {
5388 try current_thread.checkCancel();
5389 continue;
5390 },
5391 else => |e| {
5392 current_thread.endSyscall();
5393 switch (e) {
5394 .BADF => |err| return errnoBug(err),
5395 .INVAL => |err| return errnoBug(err),
5396 .ROFS => |err| return errnoBug(err),
5397 .IO => return error.InputOutput,
5398 .NOSPC => return error.NoSpaceLeft,
5399 .DQUOT => return error.DiskQuota,
5400 else => |err| return posix.unexpectedErrno(err),
5401 }
5402 },
5403 }
5404 }
5405}
5406
5369fn fileIsTty(userdata: ?*anyopaque, file: File) Io.Cancelable!bool {5407fn fileIsTty(userdata: ?*anyopaque, file: File) Io.Cancelable!bool {
5370 const t: *Threaded = @ptrCast(@alignCast(userdata));5408 const t: *Threaded = @ptrCast(@alignCast(userdata));
5371 const current_thread = Thread.getCurrent(t);5409 const current_thread = Thread.getCurrent(t);
...@@ -5659,18 +5697,16 @@ fn fileSetLength(userdata: ?*anyopaque, file: File, length: u64) File.SetLengthE...@@ -5659,18 +5697,16 @@ fn fileSetLength(userdata: ?*anyopaque, file: File, length: u64) File.SetLengthE
5659}5697}
56605698
5661fn fileSetOwner(userdata: ?*anyopaque, file: File, owner: ?File.Uid, group: ?File.Gid) File.SetOwnerError!void {5699fn fileSetOwner(userdata: ?*anyopaque, file: File, owner: ?File.Uid, group: ?File.Gid) File.SetOwnerError!void {
5662 switch (native_os) {5700 if (!have_fchown) return error.Unexpected; // Unsupported OS, don't call this function.
5663 .windows, .wasi => return error.Unexpected,
5664 else => {},
5665 }
5666 const t: *Threaded = @ptrCast(@alignCast(userdata));5701 const t: *Threaded = @ptrCast(@alignCast(userdata));
5667 const current_thread = Thread.getCurrent(t);5702 const current_thread = Thread.getCurrent(t);
5668 const uid = owner orelse ~@as(posix.uid_t, 0);5703 const uid = owner orelse ~@as(posix.uid_t, 0);
5669 const gid = group orelse ~@as(posix.gid_t, 0);5704 const gid = group orelse ~@as(posix.gid_t, 0);
5670 return setOwnerPosix(current_thread, file.handle, uid, gid);5705 return posixFchown(current_thread, file.handle, uid, gid);
5671}5706}
56725707
5673fn fileSetPermissions(userdata: ?*anyopaque, file: File, permissions: File.Permissions) File.SetPermissionsError!void {5708fn fileSetPermissions(userdata: ?*anyopaque, file: File, permissions: File.Permissions) File.SetPermissionsError!void {
5709 if (@sizeOf(File.Permissions) == 0) return;
5674 const t: *Threaded = @ptrCast(@alignCast(userdata));5710 const t: *Threaded = @ptrCast(@alignCast(userdata));
5675 const current_thread = Thread.getCurrent(t);5711 const current_thread = Thread.getCurrent(t);
5676 switch (native_os) {5712 switch (native_os) {
...@@ -5704,6 +5740,7 @@ fn fileSetPermissions(userdata: ?*anyopaque, file: File, permissions: File.Permi...@@ -5704,6 +5740,7 @@ fn fileSetPermissions(userdata: ?*anyopaque, file: File, permissions: File.Permi
5704}5740}
57055741
5706fn setPermissionsPosix(current_thread: *Thread, fd: posix.fd_t, mode: posix.mode_t) File.SetPermissionsError!void {5742fn setPermissionsPosix(current_thread: *Thread, fd: posix.fd_t, mode: posix.mode_t) File.SetPermissionsError!void {
5743 comptime assert(have_fchmod);
5707 try current_thread.beginSyscall();5744 try current_thread.beginSyscall();
5708 while (true) {5745 while (true) {
5709 switch (posix.errno(posix.system.fchmod(fd, mode))) {5746 switch (posix.errno(posix.system.fchmod(fd, mode))) {
...@@ -5987,6 +6024,7 @@ const windows_lock_range_off: windows.LARGE_INTEGER = 0;...@@ -5987,6 +6024,7 @@ const windows_lock_range_off: windows.LARGE_INTEGER = 0;
5987const windows_lock_range_len: windows.LARGE_INTEGER = 1;6024const windows_lock_range_len: windows.LARGE_INTEGER = 1;
59886025
5989fn fileLock(userdata: ?*anyopaque, file: File, lock: File.Lock) File.LockError!void {6026fn fileLock(userdata: ?*anyopaque, file: File, lock: File.Lock) File.LockError!void {
6027 if (native_os == .wasi) return error.FileLocksUnsupported;
5990 const t: *Threaded = @ptrCast(@alignCast(userdata));6028 const t: *Threaded = @ptrCast(@alignCast(userdata));
5991 const current_thread = Thread.getCurrent(t);6029 const current_thread = Thread.getCurrent(t);
59926030
...@@ -6066,6 +6104,7 @@ fn fileLock(userdata: ?*anyopaque, file: File, lock: File.Lock) File.LockError!v...@@ -6066,6 +6104,7 @@ fn fileLock(userdata: ?*anyopaque, file: File, lock: File.Lock) File.LockError!v
6066}6104}
60676105
6068fn fileTryLock(userdata: ?*anyopaque, file: File, lock: File.Lock) File.LockError!bool {6106fn fileTryLock(userdata: ?*anyopaque, file: File, lock: File.Lock) File.LockError!bool {
6107 if (native_os == .wasi) return error.FileLocksUnsupported;
6069 const t: *Threaded = @ptrCast(@alignCast(userdata));6108 const t: *Threaded = @ptrCast(@alignCast(userdata));
6070 const current_thread = Thread.getCurrent(t);6109 const current_thread = Thread.getCurrent(t);
60716110
...@@ -6150,6 +6189,7 @@ fn fileTryLock(userdata: ?*anyopaque, file: File, lock: File.Lock) File.LockErro...@@ -6150,6 +6189,7 @@ fn fileTryLock(userdata: ?*anyopaque, file: File, lock: File.Lock) File.LockErro
6150}6189}
61516190
6152fn fileUnlock(userdata: ?*anyopaque, file: File) void {6191fn fileUnlock(userdata: ?*anyopaque, file: File) void {
6192 if (native_os == .wasi) return;
6153 const t: *Threaded = @ptrCast(@alignCast(userdata));6193 const t: *Threaded = @ptrCast(@alignCast(userdata));
6154 _ = t;6194 _ = t;
61556195
...@@ -6186,6 +6226,7 @@ fn fileUnlock(userdata: ?*anyopaque, file: File) void {...@@ -6186,6 +6226,7 @@ fn fileUnlock(userdata: ?*anyopaque, file: File) void {
6186}6226}
61876227
6188fn fileDowngradeLock(userdata: ?*anyopaque, file: File) File.DowngradeLockError!void {6228fn fileDowngradeLock(userdata: ?*anyopaque, file: File) File.DowngradeLockError!void {
6229 if (native_os == .wasi) return;
6189 const t: *Threaded = @ptrCast(@alignCast(userdata));6230 const t: *Threaded = @ptrCast(@alignCast(userdata));
6190 const current_thread = Thread.getCurrent(t);6231 const current_thread = Thread.getCurrent(t);
61916232
...@@ -7072,7 +7113,7 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex...@@ -7072,7 +7113,7 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex
7072 const end_index = std.unicode.wtf16LeToWtf8(out_buffer, wide_slice);7113 const end_index = std.unicode.wtf16LeToWtf8(out_buffer, wide_slice);
7073 return end_index;7114 return end_index;
7074 },7115 },
7075 else => @compileError("unsupported OS"),7116 else => return error.OperationUnsupported,
7076 }7117 }
7077}7118}
70787119
...@@ -10034,7 +10075,10 @@ fn netWriteUnavailable(...@@ -10034,7 +10075,10 @@ fn netWriteUnavailable(
1003410075
10035/// This is either usize or u32. Since, either is fine, let's use the same10076/// This is either usize or u32. Since, either is fine, let's use the same
10036/// `addBuf` function for both writing to a file and sending network messages.10077/// `addBuf` function for both writing to a file and sending network messages.
10037const iovlen_t = @FieldType(posix.msghdr_const, "iovlen");10078const iovlen_t = switch (native_os) {
10079 .wasi => u32,
10080 else => @FieldType(posix.msghdr_const, "iovlen"),
10081};
1003810082
10039fn addBuf(v: []posix.iovec_const, i: *iovlen_t, bytes: []const u8) void {10083fn addBuf(v: []posix.iovec_const, i: *iovlen_t, bytes: []const u8) void {
10040 // OS checks ptr addr before length so zero length vectors must be omitted.10084 // OS checks ptr addr before length so zero length vectors must be omitted.
...@@ -10775,8 +10819,9 @@ fn statFromPosix(st: *const posix.Stat) File.Stat {...@@ -10775,8 +10819,9 @@ fn statFromPosix(st: *const posix.Stat) File.Stat {
10775fn statFromWasi(st: *const std.os.wasi.filestat_t) File.Stat {10819fn statFromWasi(st: *const std.os.wasi.filestat_t) File.Stat {
10776 return .{10820 return .{
10777 .inode = st.ino,10821 .inode = st.ino,
10822 .nlink = st.nlink,
10778 .size = @bitCast(st.size),10823 .size = @bitCast(st.size),
10779 .mode = 0,10824 .permissions = .default_file,
10780 .kind = switch (st.filetype) {10825 .kind = switch (st.filetype) {
10781 .BLOCK_DEVICE => .block_device,10826 .BLOCK_DEVICE => .block_device,
10782 .CHARACTER_DEVICE => .character_device,10827 .CHARACTER_DEVICE => .character_device,
lib/std/Progress.zig+2-2
...@@ -498,8 +498,8 @@ pub fn start(io: Io, options: Options) Node {...@@ -498,8 +498,8 @@ pub fn start(io: Io, options: Options) Node {
498 if (stderr.enableAnsiEscapeCodes(io)) |_| {498 if (stderr.enableAnsiEscapeCodes(io)) |_| {
499 global_progress.terminal_mode = .ansi_escape_codes;499 global_progress.terminal_mode = .ansi_escape_codes;
500 } else |_| if (is_windows) {500 } else |_| if (is_windows) {
501 if (stderr.isTty(io)) {501 if (stderr.isTty(io)) |is_tty| {
502 global_progress.terminal_mode = TerminalMode{ .windows_api = .{502 if (is_tty) global_progress.terminal_mode = TerminalMode{ .windows_api = .{
503 .code_page = windows.kernel32.GetConsoleOutputCP(),503 .code_page = windows.kernel32.GetConsoleOutputCP(),
504 } };504 } };
505 } else |err| switch (err) {505 } else |err| switch (err) {
lib/std/c.zig+3-2
...@@ -148,9 +148,10 @@ pub const dev_t = switch (native_os) {...@@ -148,9 +148,10 @@ pub const dev_t = switch (native_os) {
148pub const mode_t = switch (native_os) {148pub const mode_t = switch (native_os) {
149 .linux => linux.mode_t,149 .linux => linux.mode_t,
150 .emscripten => emscripten.mode_t,150 .emscripten => emscripten.mode_t,
151 .openbsd, .haiku, .netbsd, .illumos, .wasi, .windows => u32,151 .openbsd, .haiku, .netbsd, .illumos, .windows => u32,
152 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L44152 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L44
153 .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .dragonfly, .serenity => u16,153 .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .dragonfly, .serenity => u16,
154 .wasi => if (builtin.link_libc) u32 else u0, // WASI libc emulates mode.
154 else => u0,155 else => u0,
155};156};
156157
...@@ -10608,7 +10609,7 @@ pub extern "c" fn munmap(addr: *align(page_size) const anyopaque, len: usize) c_...@@ -10608,7 +10609,7 @@ pub extern "c" fn munmap(addr: *align(page_size) const anyopaque, len: usize) c_
10608pub extern "c" fn mremap(addr: ?*align(page_size) const anyopaque, old_len: usize, new_len: usize, flags: MREMAP, ...) *anyopaque;10609pub extern "c" fn mremap(addr: ?*align(page_size) const anyopaque, old_len: usize, new_len: usize, flags: MREMAP, ...) *anyopaque;
10609pub extern "c" fn mprotect(addr: *align(page_size) anyopaque, len: usize, prot: c_uint) c_int;10610pub extern "c" fn mprotect(addr: *align(page_size) anyopaque, len: usize, prot: c_uint) c_int;
10610pub extern "c" fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8) c_int;10611pub extern "c" fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8) c_int;
10611pub extern "c" fn linkat(oldfd: fd_t, oldpath: [*:0]const u8, newfd: fd_t, newpath: [*:0]const u8, flags: c_int) c_int;10612pub extern "c" fn linkat(oldfd: fd_t, oldpath: [*:0]const u8, newfd: fd_t, newpath: [*:0]const u8, flags: c_uint) c_int;
10612pub extern "c" fn unlink(path: [*:0]const u8) c_int;10613pub extern "c" fn unlink(path: [*:0]const u8) c_int;
10613pub extern "c" fn unlinkat(dirfd: fd_t, path: [*:0]const u8, flags: c_uint) c_int;10614pub extern "c" fn unlinkat(dirfd: fd_t, path: [*:0]const u8, flags: c_uint) c_int;
10614pub extern "c" fn getcwd(buf: [*]u8, size: usize) ?[*]u8;10615pub extern "c" fn getcwd(buf: [*]u8, size: usize) ?[*]u8;
lib/std/process.zig+3-1
...@@ -2121,7 +2121,9 @@ pub fn fatal(comptime format: []const u8, format_arguments: anytype) noreturn {...@@ -2121,7 +2121,9 @@ pub fn fatal(comptime format: []const u8, format_arguments: anytype) noreturn {
2121pub const ExecutablePathBaseError = error{2121pub const ExecutablePathBaseError = error{
2122 FileNotFound,2122 FileNotFound,
2123 AccessDenied,2123 AccessDenied,
2124 NotSupported,2124 /// The operating system does not support an executable learning its own
2125 /// path.
2126 OperationUnsupported,
2125 NotDir,2127 NotDir,
2126 SymLinkLoop,2128 SymLinkLoop,
2127 InputOutput,2129 InputOutput,