47 lines
1 KiB
C
47 lines
1 KiB
C
#include "log.h"
|
|
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
char *read_text_file(char *path) {
|
|
FILE *file = fopen(path, "r");
|
|
if (file == NULL) {
|
|
meow("Could not open file %s", path);
|
|
return NULL;
|
|
}
|
|
fseek(file, 0, SEEK_END);
|
|
long size = ftell(file);
|
|
fseek(file, 0, SEEK_SET);
|
|
|
|
char *content = malloc((size + 1) * sizeof(char));
|
|
|
|
long count = fread(content, sizeof(char), size, file);
|
|
if (count < size) {
|
|
content = realloc(content, count + 1);
|
|
}
|
|
content[count] = 0x00;
|
|
fclose(file);
|
|
return content;
|
|
}
|
|
|
|
uint32_t *read_binary_file(char *path, int *size) {
|
|
FILE *file = fopen(path, "r");
|
|
if (file == NULL) {
|
|
meow("Could not open file %s", path);
|
|
return NULL;
|
|
}
|
|
fseek(file, 0, SEEK_END);
|
|
long fsize = ftell(file);
|
|
*size = fsize;
|
|
fseek(file, 0, SEEK_SET);
|
|
|
|
char *content = malloc((fsize) * sizeof(char));
|
|
|
|
long count = fread(content, sizeof(char), fsize, file);
|
|
if (count < fsize) {
|
|
content = realloc(content, count);
|
|
}
|
|
fclose(file);
|
|
return (uint32_t *)content;
|
|
}
|