21 lines
460 B
C

#include "io.h"
char* read_file(const char* filePath) {
FILE* file = fopen(filePath, "rb");
if (file == NULL) {
fprintf(stderr, "Error: Could not open file %s\n", filePath);
return NULL;
}
fseek(file, 0, SEEK_END);
long length = ftell(file);
fseek(file, 0, SEEK_SET);
char* buffer = (char*)malloc(length + 1);
fread(buffer, 1, length, file);
buffer[length] = '\0';
fclose(file);
return buffer;
}