authorgravatar for carmen@dotcarmen.devCarmen <carmen@dotcarmen.dev> 2025-04-02 23:34:48+02:00
committergravatar for mail@linusgroh.deLinus Groh <mail@linusgroh.de> 2025-04-04 12:42:28+01:00
loga61678b7549d0113ea30f269b30ccb8e44dc978b
treecff789f258034771a0d50619ec237cb0f2398ade
parent45afde2036fdacf5a5fc381acfad5982a4b84810

dont return tuple, split into 2 functions


1 files changed, 26 insertions(+), 9 deletions(-)

lib/std/os/uefi/protocol/file.zig+26-9
......@@ -52,12 +52,15 @@ pub const File = extern struct {
5252 AccessDenied,
5353 VolumeFull,
5454 };
55 pub const GetInfoError = uefi.UnexpectedError || error{
55 pub const GetInfoSizeError = uefi.UnexpectedError || error{
5656 Unsupported,
5757 NoMedia,
5858 DeviceError,
5959 VolumeCorrupted,
6060 };
61 pub const GetInfoError = GetInfoSizeError || error{
62 BufferTooSmall,
63 };
6164 pub const SetInfoError = uefi.UnexpectedError || error{
6265 Unsupported,
6366 NoMedia,
......@@ -215,25 +218,39 @@ pub const File = extern struct {
215218 try self.setPosition(pos);
216219 }
217220
218 /// If the underlying function returns `.buffer_too_small`, then this function
219 /// returns `.{ len, null }`. Otherwise, the 2nd value of the tuple contains
220 /// the casted reference from the buffer.
221 pub fn getInfoSize(self: *const File, comptime info: std.meta.Tag(Info)) GetInfoError!usize {
222 const InfoType = @FieldType(Info, @tagName(info));
223
224 var len: usize = 0;
225 switch (self._get_info(self, &InfoType.guid, &len, null)) {
226 .success, .buffer_too_small => return len,
227 .unsupported => return Error.Unsupported,
228 .no_media => return Error.NoMedia,
229 .device_error => return Error.DeviceError,
230 .volume_corrupted => return Error.VolumeCorrupted,
231 else => |status| return uefi.unexpectedStatus(status),
232 }
233 }
234
235 /// If `buffer` is too small to contain all of the info, this function returns
236 /// `Error.BufferTooSmall`. You should call `getInfoSize` first to determine
237 /// how big the buffer should be to safely call this function.
221238 pub fn getInfo(
222239 self: *const File,
223240 comptime info: std.meta.Tag(Info),
224 buffer: ?[]u8,
241 buffer: []u8,
225242 ) GetInfoError!struct { usize, @FieldType(Info, @tagName(info)) } {
226243 const InfoType = @FieldType(Info, @tagName(info));
227244
228 var len = if (buffer) |b| b.len else 0;
245 var len = buffer.len;
229246 switch (self._get_info(
230247 self,
231248 &InfoType.guid,
232249 &len,
233 if (buffer) |b| b else null,
250 buffer.ptr,
234251 )) {
235 .success => return .{ len, @as(*InfoType, @ptrCast(buffer.ptr)) },
236 .buffer_too_small => return .{ len, null },
252 .success => return @as(*InfoType, @ptrCast(buffer.ptr)),
253 .buffer_too_small => return Error.BufferTooSmall,
237254 .unsupported => return Error.Unsupported,
238255 .no_media => return Error.NoMedia,
239256 .device_error => return Error.DeviceError,