56 lines
1.3 KiB
C
56 lines
1.3 KiB
C
#include "link.h"
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
int link_kern(const Args* args, FileIter input_files)
|
|
{
|
|
int res = 0;
|
|
|
|
FILE* output_fp = fopen(args->output_file, "wb");
|
|
if (!output_fp) {
|
|
fprintf(stderr,
|
|
"could not open output file '%s' for writing: %s\n",
|
|
args->output_file,
|
|
strerror(errno));
|
|
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 = fopen(input_filename, "rb");
|
|
if (!input_fp) {
|
|
fprintf(stderr,
|
|
"could not open input file '%s' for reading: %s\n",
|
|
input_filename,
|
|
strerror(errno));
|
|
goto leave_1;
|
|
}
|
|
|
|
int read_res = header_read_from(&header, input_fp, input_filename);
|
|
if (read_res != 0) {
|
|
res = -1;
|
|
goto leave_1;
|
|
}
|
|
header_print(&header);
|
|
|
|
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);
|
|
leave_0:
|
|
return res;
|
|
}
|