add reading file

This commit is contained in:
2025-03-23 22:28:52 +03:00
parent f88718422e
commit 630ff582fb

View File

@@ -9,6 +9,11 @@
static const char* str_usage = "Usage: %s [--nologo / -n] [--kernel / -k] [--unpack / -u] <infile> [<outfile>]\n"; static const char* str_usage = "Usage: %s [--nologo / -n] [--kernel / -k] [--unpack / -u] <infile> [<outfile>]\n";
static void error_load_infile() {
printf("Error: cannot load input file\n");
exit(1);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
bool flag_nologo = false; bool flag_nologo = false;
@@ -75,8 +80,7 @@ int main(int argc, char *argv[])
struct stat64 statbuf; struct stat64 statbuf;
int res_stat = stat64(infile_name, &statbuf); int res_stat = stat64(infile_name, &statbuf);
if (res_stat == -1) { if (res_stat == -1) {
printf("Error: cannot load input file\n"); error_load_infile();
return 1;
} }
// printf("statbuf.st_size = %lld\n", statbuf.st_size); // printf("statbuf.st_size = %lld\n", statbuf.st_size);
@@ -89,9 +93,23 @@ int main(int argc, char *argv[])
FILE *infile_handle = fopen(infile_name, "rb"); FILE *infile_handle = fopen(infile_name, "rb");
if (!infile_handle) { if (!infile_handle) {
printf("Error: cannot load input file\n"); error_load_infile();
}
unsigned char *infile_buf = malloc(infile_size);
if (infile_buf == NULL) {
printf("Error: memory allocation failed\n");
return 1; return 1;
} }
size_t bytes_read = fread(infile_buf, 1, infile_size, infile_handle);
if (bytes_read != infile_size) {
error_load_infile();
}
fclose(infile_handle);
// printf("file contents = %s\n", infile_buf);
// TODO ...
return 0; return 0;
} }