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 {...@@ -20,12 +20,12 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
20 var stream = std.io.fixedBufferStream(bytes);20 var stream = std.io.fixedBufferStream(bytes);
21 const reader = stream.reader();21 const reader = stream.reader();
2222
23 const db_header = try reader.readStructBig(ApplDbHeader);23 const db_header = try reader.readStructEndian(ApplDbHeader, .big);
24 assert(mem.eql(u8, "kych", &@as([4]u8, @bitCast(db_header.signature))));24 assert(mem.eql(u8, "kych", &@as([4]u8, @bitCast(db_header.signature))));
2525
26 try stream.seekTo(db_header.schema_offset);26 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
30 var table_list = try gpa.alloc(u32, db_schema.table_count);30 var table_list = try gpa.alloc(u32, db_schema.table_count);
31 defer gpa.free(table_list);31 defer gpa.free(table_list);
...@@ -40,7 +40,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {...@@ -40,7 +40,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
40 for (table_list) |table_offset| {40 for (table_list) |table_offset| {
41 try stream.seekTo(db_header.schema_offset + table_offset);41 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
45 if (@as(std.os.darwin.cssm.DB_RECORDTYPE, @enumFromInt(table_header.table_id)) != .X509_CERTIFICATE) {45 if (@as(std.os.darwin.cssm.DB_RECORDTYPE, @enumFromInt(table_header.table_id)) != .X509_CERTIFICATE) {
46 continue;46 continue;
...@@ -57,7 +57,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {...@@ -57,7 +57,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
57 for (record_list) |record_offset| {57 for (record_list) |record_offset| {
58 try stream.seekTo(db_header.schema_offset + table_offset + record_offset);58 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
62 try cb.bytes.ensureUnusedCapacity(gpa, cert_header.cert_size);62 try cb.bytes.ensureUnusedCapacity(gpa, cert_header.cert_size);
6363
lib/std/io.zig+2-2
...@@ -300,8 +300,8 @@ pub fn GenericReader(...@@ -300,8 +300,8 @@ pub fn GenericReader(
300 return @errorCast(self.any().readStruct(T));300 return @errorCast(self.any().readStruct(T));
301 }301 }
302302
303 pub inline fn readStructBig(self: Self, comptime T: type) NoEofError!T {303 pub inline fn readStructEndian(self: Self, comptime T: type, endian: std.builtin.Endian) NoEofError!T {
304 return @errorCast(self.any().readStructBig(T));304 return @errorCast(self.any().readStructEndian(T, endian));
305 }305 }
306306
307 pub const ReadEnumError = NoEofError || error{307 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 {...@@ -332,9 +332,9 @@ pub fn readStruct(self: Self, comptime T: type) anyerror!T {
332 return res[0];332 return res[0];
333}333}
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 {
336 var res = try self.readStruct(T);336 var res = try self.readStruct(T);
337 if (native_endian != std.builtin.Endian.big) {337 if (native_endian != endian) {
338 mem.byteSwapAllFields(T, &res);338 mem.byteSwapAllFields(T, &res);
339 }339 }
340 return res;340 return res;
src/link/MachO/fat.zig+3-3
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1pub fn isFatLibrary(file: std.fs.File) bool {1pub fn isFatLibrary(file: std.fs.File) bool {
2 const reader = file.reader();2 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;
4 defer file.seekTo(0) catch {};4 defer file.seekTo(0) catch {};
5 return hdr.magic == macho.FAT_MAGIC;5 return hdr.magic == macho.FAT_MAGIC;
6}6}
...@@ -13,7 +13,7 @@ pub const Arch = struct {...@@ -13,7 +13,7 @@ pub const Arch = struct {
13/// Caller owns the memory.13/// Caller owns the memory.
14pub fn parseArchs(gpa: Allocator, file: std.fs.File) ![]const Arch {14pub fn parseArchs(gpa: Allocator, file: std.fs.File) ![]const Arch {
15 const reader = file.reader();15 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);
17 assert(fat_header.magic == macho.FAT_MAGIC);17 assert(fat_header.magic == macho.FAT_MAGIC);
1818
19 var archs = try std.ArrayList(Arch).initCapacity(gpa, fat_header.nfat_arch);19 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 {...@@ -21,7 +21,7 @@ pub fn parseArchs(gpa: Allocator, file: std.fs.File) ![]const Arch {
2121
22 var fat_arch_index: u32 = 0;22 var fat_arch_index: u32 = 0;
23 while (fat_arch_index < fat_header.nfat_arch) : (fat_arch_index += 1) {23 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);
25 // If we come across an architecture that we do not know how to handle, that's25 // If we come across an architecture that we do not know how to handle, that's
26 // fine because we can keep looking for one that might match.26 // fine because we can keep looking for one that might match.
27 const arch: std.Target.Cpu.Arch = switch (fat_arch.cputype) {27 const arch: std.Target.Cpu.Arch = switch (fat_arch.cputype) {