authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2023-03-08 01:06:50-08:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-03-19 17:33:25+01:00
log2fce991d2ab1dfc6d591b560607ef0edecc7db19
treec9bcc52ef9ae806af9dee11b19bd31deb37023ba
parentc26cbd561c812a8915bc3c3480358b0f2be10de0

Remove std.os.windows.QueryInformationFile (a wrapper of NtQueryInformationFile)

This function is unused, and the current implementation contains a few footguns: - The current wrapper treats all possible errors as unexpected, even likely ones like BUFFER_OVERFLOW (which is returned if the size of the out_buffer is too small to contain all the variable-length members of the requested info, which the user may not actually care about) - Each caller may need to handle errors differently, different errors might be possible depending on the FILE_INFORMATION_CLASS, etc, and making a wrapper that handles all of those different use-cases nicely seems like it'd be more trouble than it's worth (FILE_INFORMATION_CLASS has 76 different possible values) If a wrapper for NtQueryInformationFile is wanted, then it should probably have wrapper functions per-use-case, like how QueryObjectName wraps NtQueryObject for the `ObjectNameInformation` class

1 files changed, 0 insertions(+), 17 deletions(-)

lib/std/os/windows.zig-17
...@@ -1230,23 +1230,6 @@ test "GetFinalPathNameByHandle" {...@@ -1230,23 +1230,6 @@ test "GetFinalPathNameByHandle" {
1230 _ = try GetFinalPathNameByHandle(handle, .{ .volume_name = .Dos }, buffer[0..required_len_in_u16]);1230 _ = try GetFinalPathNameByHandle(handle, .{ .volume_name = .Dos }, buffer[0..required_len_in_u16]);
1231}1231}
12321232
1233pub const QueryInformationFileError = error{Unexpected};
1234
1235pub fn QueryInformationFile(
1236 handle: HANDLE,
1237 info_class: FILE_INFORMATION_CLASS,
1238 out_buffer: []u8,
1239) QueryInformationFileError!void {
1240 var io: IO_STATUS_BLOCK = undefined;
1241 const len_bytes = std.math.cast(u32, out_buffer.len) orelse unreachable;
1242 const rc = ntdll.NtQueryInformationFile(handle, &io, out_buffer.ptr, len_bytes, info_class);
1243 switch (rc) {
1244 .SUCCESS => {},
1245 .INVALID_PARAMETER => unreachable,
1246 else => return unexpectedStatus(rc),
1247 }
1248}
1249
1250pub const GetFileSizeError = error{Unexpected};1233pub const GetFileSizeError = error{Unexpected};
12511234
1252pub fn GetFileSizeEx(hFile: HANDLE) GetFileSizeError!u64 {1235pub fn GetFileSizeEx(hFile: HANDLE) GetFileSizeError!u64 {