24 lines
521 B
C++
24 lines
521 B
C++
#include <cstdio>
|
|
#include <stdlib.h>
|
|
|
|
#include "util.hpp"
|
|
|
|
bool read_file(array<char>* out, const char* filepath) {
|
|
FILE* fp = NULL;
|
|
if (fopen_s(&fp, filepath, "rb") != 0) {
|
|
printf("ERROR Failed to open file %s\n", filepath);
|
|
return false;
|
|
}
|
|
|
|
fseek(fp, 0L, SEEK_END);
|
|
size_t sz = ftell(fp);
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
char *data = (char*)malloc(sizeof(char)*sz);
|
|
fread(data, sizeof(char), sz, fp);
|
|
fclose(fp);
|
|
out->data = data;
|
|
out->len = sz;
|
|
return true;
|
|
}
|