mirror of
https://github.com/ziglang/zig.git
synced 2025-12-17 19:53:06 +00:00
dont return tuple, split into 2 functions
This commit is contained in:
parent
45afde2036
commit
a61678b754
@ -52,12 +52,15 @@ pub const File = extern struct {
|
|||||||
AccessDenied,
|
AccessDenied,
|
||||||
VolumeFull,
|
VolumeFull,
|
||||||
};
|
};
|
||||||
pub const GetInfoError = uefi.UnexpectedError || error{
|
pub const GetInfoSizeError = uefi.UnexpectedError || error{
|
||||||
Unsupported,
|
Unsupported,
|
||||||
NoMedia,
|
NoMedia,
|
||||||
DeviceError,
|
DeviceError,
|
||||||
VolumeCorrupted,
|
VolumeCorrupted,
|
||||||
};
|
};
|
||||||
|
pub const GetInfoError = GetInfoSizeError || error{
|
||||||
|
BufferTooSmall,
|
||||||
|
};
|
||||||
pub const SetInfoError = uefi.UnexpectedError || error{
|
pub const SetInfoError = uefi.UnexpectedError || error{
|
||||||
Unsupported,
|
Unsupported,
|
||||||
NoMedia,
|
NoMedia,
|
||||||
@ -215,25 +218,39 @@ pub const File = extern struct {
|
|||||||
try self.setPosition(pos);
|
try self.setPosition(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If the underlying function returns `.buffer_too_small`, then this function
|
pub fn getInfoSize(self: *const File, comptime info: std.meta.Tag(Info)) GetInfoError!usize {
|
||||||
/// returns `.{ len, null }`. Otherwise, the 2nd value of the tuple contains
|
const InfoType = @FieldType(Info, @tagName(info));
|
||||||
/// the casted reference from the buffer.
|
|
||||||
|
var len: usize = 0;
|
||||||
|
switch (self._get_info(self, &InfoType.guid, &len, null)) {
|
||||||
|
.success, .buffer_too_small => return len,
|
||||||
|
.unsupported => return Error.Unsupported,
|
||||||
|
.no_media => return Error.NoMedia,
|
||||||
|
.device_error => return Error.DeviceError,
|
||||||
|
.volume_corrupted => return Error.VolumeCorrupted,
|
||||||
|
else => |status| return uefi.unexpectedStatus(status),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// If `buffer` is too small to contain all of the info, this function returns
|
||||||
|
/// `Error.BufferTooSmall`. You should call `getInfoSize` first to determine
|
||||||
|
/// how big the buffer should be to safely call this function.
|
||||||
pub fn getInfo(
|
pub fn getInfo(
|
||||||
self: *const File,
|
self: *const File,
|
||||||
comptime info: std.meta.Tag(Info),
|
comptime info: std.meta.Tag(Info),
|
||||||
buffer: ?[]u8,
|
buffer: []u8,
|
||||||
) GetInfoError!struct { usize, @FieldType(Info, @tagName(info)) } {
|
) GetInfoError!struct { usize, @FieldType(Info, @tagName(info)) } {
|
||||||
const InfoType = @FieldType(Info, @tagName(info));
|
const InfoType = @FieldType(Info, @tagName(info));
|
||||||
|
|
||||||
var len = if (buffer) |b| b.len else 0;
|
var len = buffer.len;
|
||||||
switch (self._get_info(
|
switch (self._get_info(
|
||||||
self,
|
self,
|
||||||
&InfoType.guid,
|
&InfoType.guid,
|
||||||
&len,
|
&len,
|
||||||
if (buffer) |b| b else null,
|
buffer.ptr,
|
||||||
)) {
|
)) {
|
||||||
.success => return .{ len, @as(*InfoType, @ptrCast(buffer.ptr)) },
|
.success => return @as(*InfoType, @ptrCast(buffer.ptr)),
|
||||||
.buffer_too_small => return .{ len, null },
|
.buffer_too_small => return Error.BufferTooSmall,
|
||||||
.unsupported => return Error.Unsupported,
|
.unsupported => return Error.Unsupported,
|
||||||
.no_media => return Error.NoMedia,
|
.no_media => return Error.NoMedia,
|
||||||
.device_error => return Error.DeviceError,
|
.device_error => return Error.DeviceError,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user