macho+zld: clean up opening and closing of file descriptors

This commit is contained in:
Jakub Konka 2023-03-17 17:54:47 +01:00
parent 76afdd0586
commit ee705e3ac7

View File

@ -3665,16 +3665,17 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
} else {
const page_size = macho_file.page_size;
const sub_path = options.emit.?.sub_path;
if (macho_file.base.file == null) {
macho_file.base.file = try directory.handle.createFile(sub_path, .{
.truncate = true,
.read = true,
.mode = link.determineMode(options.*),
});
}
const file = try directory.handle.createFile(sub_path, .{
.truncate = true,
.read = true,
.mode = link.determineMode(options.*),
});
defer file.close();
var zld = Zld{
.gpa = gpa,
.file = macho_file.base.file.?,
.file = file,
.page_size = macho_file.page_size,
.options = options,
};