authorgravatar for tristan.ross@midstall.comTristan Ross <tristan.ross@midstall.com> 2024-01-21 21:38:08-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-22 10:53:27-08:00
logd0da3d731e40fe9e0b45d50d4c3bf8210b44d472
tree3cf117d8843c72440b063570d598d89335f55254
parentb0c8a3f31631a63bca3a2feece38e57b9a1c5060

std.io: replace readStructBig with readStructEndian


4 files changed, 11 insertions(+), 11 deletions(-)

lib/std/crypto/Certificate/Bundle/macos.zig+4-4
......@@ -20,12 +20,12 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
2020 var stream = std.io.fixedBufferStream(bytes);
2121 const reader = stream.reader();
2222
23 const db_header = try reader.readStructBig(ApplDbHeader);
23 const db_header = try reader.readStructEndian(ApplDbHeader, .big);
2424 assert(mem.eql(u8, "kych", &@as([4]u8, @bitCast(db_header.signature))));
2525
2626 try stream.seekTo(db_header.schema_offset);
2727
28 const db_schema = try reader.readStructBig(ApplDbSchema);
28 const db_schema = try reader.readStructEndian(ApplDbSchema, .big);
2929
3030 var table_list = try gpa.alloc(u32, db_schema.table_count);
3131 defer gpa.free(table_list);
......@@ -40,7 +40,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
4040 for (table_list) |table_offset| {
4141 try stream.seekTo(db_header.schema_offset + table_offset);
4242
43 const table_header = try reader.readStructBig(TableHeader);
43 const table_header = try reader.readStructEndian(TableHeader, .big);
4444
4545 if (@as(std.os.darwin.cssm.DB_RECORDTYPE, @enumFromInt(table_header.table_id)) != .X509_CERTIFICATE) {
4646 continue;
......@@ -57,7 +57,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
5757 for (record_list) |record_offset| {
5858 try stream.seekTo(db_header.schema_offset + table_offset + record_offset);
5959
60 const cert_header = try reader.readStructBig(X509CertHeader);
60 const cert_header = try reader.readStructEndian(X509CertHeader, .big);
6161
6262 try cb.bytes.ensureUnusedCapacity(gpa, cert_header.cert_size);
6363
lib/std/io.zig+2-2
......@@ -300,8 +300,8 @@ pub fn GenericReader(
300300 return @errorCast(self.any().readStruct(T));
301301 }
302302
303 pub inline fn readStructBig(self: Self, comptime T: type) NoEofError!T {
304 return @errorCast(self.any().readStructBig(T));
303 pub inline fn readStructEndian(self: Self, comptime T: type, endian: std.builtin.Endian) NoEofError!T {
304 return @errorCast(self.any().readStructEndian(T, endian));
305305 }
306306
307307 pub const ReadEnumError = NoEofError || error{
lib/std/io/Reader.zig+2-2
......@@ -332,9 +332,9 @@ pub fn readStruct(self: Self, comptime T: type) anyerror!T {
332332 return res[0];
333333}
334334
335pub fn readStructBig(self: Self, comptime T: type) anyerror!T {
335pub fn readStructEndian(self: Self, comptime T: type, endian: std.builtin.Endian) anyerror!T {
336336 var res = try self.readStruct(T);
337 if (native_endian != std.builtin.Endian.big) {
337 if (native_endian != endian) {
338338 mem.byteSwapAllFields(T, &res);
339339 }
340340 return res;
src/link/MachO/fat.zig+3-3
......@@ -1,6 +1,6 @@
11pub fn isFatLibrary(file: std.fs.File) bool {
22 const reader = file.reader();
3 const hdr = reader.readStructBig(macho.fat_header) catch return false;
3 const hdr = reader.readStructEndian(macho.fat_header, .big) catch return false;
44 defer file.seekTo(0) catch {};
55 return hdr.magic == macho.FAT_MAGIC;
66}
......@@ -13,7 +13,7 @@ pub const Arch = struct {
1313/// Caller owns the memory.
1414pub fn parseArchs(gpa: Allocator, file: std.fs.File) ![]const Arch {
1515 const reader = file.reader();
16 const fat_header = try reader.readStructBig(macho.fat_header);
16 const fat_header = try reader.readStructEndian(macho.fat_header, .big);
1717 assert(fat_header.magic == macho.FAT_MAGIC);
1818
1919 var archs = try std.ArrayList(Arch).initCapacity(gpa, fat_header.nfat_arch);
......@@ -21,7 +21,7 @@ pub fn parseArchs(gpa: Allocator, file: std.fs.File) ![]const Arch {
2121
2222 var fat_arch_index: u32 = 0;
2323 while (fat_arch_index < fat_header.nfat_arch) : (fat_arch_index += 1) {
24 const fat_arch = try reader.readStructBig(macho.fat_arch);
24 const fat_arch = try reader.readStructEndian(macho.fat_arch, .big);
2525 // If we come across an architecture that we do not know how to handle, that's
2626 // fine because we can keep looking for one that might match.
2727 const arch: std.Target.Cpu.Arch = switch (fat_arch.cputype) {