started impl allocation
This commit is contained in:
21
kpack_c.c
21
kpack_c.c
@@ -14,6 +14,11 @@ static void error_load_infile() {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void error_malloc_failed() {
|
||||||
|
printf("Error: memory allocation failed\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
bool flag_nologo = false;
|
bool flag_nologo = false;
|
||||||
@@ -44,7 +49,7 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check for required infile
|
// check for required infile
|
||||||
if (optind >= argc) {
|
if (optind >= argc) {
|
||||||
printf("Error: Input file is required.\n");
|
printf("Error: Input file is required.\n");
|
||||||
printf(str_usage, argv[0]);
|
printf(str_usage, argv[0]);
|
||||||
@@ -52,7 +57,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
infile_name = argv[optind];
|
infile_name = argv[optind];
|
||||||
|
|
||||||
// Optional outfile
|
// optional outfile
|
||||||
if (optind + 1 < argc) {
|
if (optind + 1 < argc) {
|
||||||
outfile_name = argv[optind + 1];
|
outfile_name = argv[optind + 1];
|
||||||
optind++;
|
optind++;
|
||||||
@@ -98,8 +103,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
unsigned char *infile_buf = malloc(infile_size);
|
unsigned char *infile_buf = malloc(infile_size);
|
||||||
if (infile_buf == NULL) {
|
if (infile_buf == NULL) {
|
||||||
printf("Error: memory allocation failed\n");
|
error_malloc_failed();
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
size_t bytes_read = fread(infile_buf, 1, infile_size, infile_handle);
|
size_t bytes_read = fread(infile_buf, 1, infile_size, infile_handle);
|
||||||
if (bytes_read != infile_size) {
|
if (bytes_read != infile_size) {
|
||||||
@@ -107,9 +111,16 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
fclose(infile_handle);
|
fclose(infile_handle);
|
||||||
|
|
||||||
// printf("file contents = %s\n", infile_buf);
|
// calculate maximum size of the output:
|
||||||
|
unsigned bufsize = infile_size*9/8 + 0x400; // should be enough for header
|
||||||
|
printf("bufsize = 0x%x\n", bufsize);
|
||||||
|
unsigned char *buf = malloc(2*bufsize); // allocate memory for two copies of maximum output
|
||||||
|
if (buf == NULL) {
|
||||||
|
error_malloc_failed();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO ...
|
// TODO ...
|
||||||
|
// https://git.kolibrios.org/KolibriOS/kolibrios/src/commit/293e1d195a14d01a0f8812a954ff1449048f6209/programs/other/kpack/kerpack_linux/kpack64.asm#L236
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Reference in New Issue
Block a user