| ... | @@ -285,15 +285,9 @@ pub fn checkDuplicates(self: *ZigObject, dupes: anytype, macho_file: *MachO) !vo | ... | @@ -285,15 +285,9 @@ pub fn checkDuplicates(self: *ZigObject, dupes: anytype, macho_file: *MachO) !vo |
| 285 | /// This is just a temporary helper function that allows us to re-read what we wrote to file into a buffer. | 285 | /// This is just a temporary helper function that allows us to re-read what we wrote to file into a buffer. |
| 286 | /// We need this so that we can write to an archive. | 286 | /// We need this so that we can write to an archive. |
| 287 | /// TODO implement writing ZigObject data directly to a buffer instead. | 287 | /// TODO implement writing ZigObject data directly to a buffer instead. |
| 288 | pub fn readFileContents(self: *ZigObject, macho_file: *MachO) !void { | 288 | pub fn readFileContents(self: *ZigObject, size: usize, macho_file: *MachO) !void { |
| 289 | const gpa = macho_file.base.comp.gpa; | 289 | const gpa = macho_file.base.comp.gpa; |
| 290 | var end_pos: u64 = 0; | | |
| 291 | for (macho_file.segments.items) |seg| { | | |
| 292 | end_pos = @max(end_pos, seg.fileoff + seg.filesize); | | |
| 293 | } | | |
| 294 | const size = std.math.cast(usize, end_pos) orelse return error.Overflow; | | |
| 295 | try self.data.resize(gpa, size); | 290 | try self.data.resize(gpa, size); |
| 296 | | | |
| 297 | const amt = try macho_file.base.file.?.preadAll(self.data.items, 0); | 291 | const amt = try macho_file.base.file.?.preadAll(self.data.items, 0); |
| 298 | if (amt != size) return error.InputOutput; | 292 | if (amt != size) return error.InputOutput; |
| 299 | } | 293 | } |