wip
This commit is contained in:
20
crc_util.c
20
crc_util.c
@@ -41,3 +41,23 @@ int create_cc_file(unsigned char *addr, unsigned long file_length) {
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
unsigned char* file_to_char_array(FILE *in_file, size_t* size) {
|
||||
unsigned int c;
|
||||
unsigned long file_data_cap = 8;
|
||||
unsigned char* file_data = calloc(file_data_cap, sizeof(unsigned char));
|
||||
|
||||
for(size_t i = 0;(c = fgetc(in_file)) != EOF; i++) {
|
||||
if(i == file_data_cap) {
|
||||
file_data_cap *= 2;
|
||||
file_data = reallocarray(file_data, file_data_cap, sizeof(unsigned char));
|
||||
if(file_data == NULL) {
|
||||
perror("FAILED ARRAY RESIZE");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
file_data[i] = c;
|
||||
*size += 1;
|
||||
}
|
||||
return file_data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user