From 8b2d0ce218db8d874cec1c11b3f186955af620c1 Mon Sep 17 00:00:00 2001 From: gDator Date: Thu, 23 Jul 2026 23:06:12 +0200 Subject: [PATCH] Io.Threaded: Implement fileLength without fileStat on Windows (#36293) Closes #36179 Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36293 Reviewed-by: Ryan Liptak --- lib/std/Io/Threaded.zig | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index 04384b3d68e4e8c26f610731479f4ec435c7cc44..457e4a255f857a80bd7f487b52c9db83027a4370 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -3858,7 +3858,26 @@ fn fileLength(userdata: ?*anyopaque, file: File) File.LengthError!u64 { } } } else if (is_windows) { - // TODO call NtQueryInformationFile and ask for only the size instead of "all" + var io_status_block: windows.IO_STATUS_BLOCK = undefined; + var info: windows.FILE.STANDARD_INFORMATION = undefined; + const syscall: Syscall = try .start(); + while (true) switch (windows.ntdll.NtQueryInformationFile( + file.handle, + &io_status_block, + &info, + @sizeOf(windows.FILE.STANDARD_INFORMATION), + .Standard, + )) { + .SUCCESS => break syscall.finish(), + .INVALID_PARAMETER => |err| return syscall.ntstatusBug(err), + .ACCESS_DENIED => return syscall.fail(error.AccessDenied), + .CANCELLED => { + try syscall.checkCancel(); + continue; + }, + else => |s| return syscall.unexpectedNtstatus(s), + }; + return @as(u64, @bitCast(info.EndOfFile)); } const stat = try fileStat(t, file); -- 2.54.0