add reading file
This commit is contained in:
24
kpack_c.c
24
kpack_c.c
@@ -9,6 +9,11 @@
|
||||
|
||||
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[])
|
||||
{
|
||||
bool flag_nologo = false;
|
||||
@@ -75,8 +80,7 @@ int main(int argc, char *argv[])
|
||||
struct stat64 statbuf;
|
||||
int res_stat = stat64(infile_name, &statbuf);
|
||||
if (res_stat == -1) {
|
||||
printf("Error: cannot load input file\n");
|
||||
return 1;
|
||||
error_load_infile();
|
||||
}
|
||||
// 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");
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
Reference in New Issue
Block a user