#include "header.h" #include "link.h" #include "sym.h" #include #include int link_kern(const Args* args, FileIter input_files) { int res = 0; SymTable sym_table; sym_table_construct(&sym_table); SymTable* syms = &sym_table; uint16_t offset = 0; FILE* output_fp = open_output_file(args->output_file); if (!output_fp) { res = -1; goto leave_0; } FILE* input_fp = NULL; Header header = (Header) { 0 }; const char* input_filename = file_iter_next(&input_files); while (input_filename != NULL) { input_fp = open_input_file(input_filename); if (!input_fp) { res = -1; goto leave_0; } res = header_read_from(&header, input_fp, input_filename); if (res != 0) goto leave_1; header_print(&header); sym_table_walk_header(syms, &header, offset, input_filename); fclose(input_fp); input_fp = NULL; input_filename = file_iter_next(&input_files); } res = 0; leave_1: if (input_fp) fclose(input_fp); if (header.header_size != 0) header_destroy(&header); fclose(output_fp); sym_table_destroy(&sym_table); leave_0: return res; }