#include #include #include "util.h" const uint MAX_FILESIZE = 2 * 1024 * 1024; // 2MB char * utilDumpTextFile(const char* filename) { // log('info: loading filename, blablabla); // TODO: log errors std::FILE* fp = std::fopen(filename, "rb"); assert(fp); std::fseek(fp, 0, SEEK_END); uint length = std::ftell(fp); std::fseek(fp, 0, SEEK_SET); assert(length < MAX_FILESIZE); // TODO: check error codes for fseek and ftell char* buf = (char *) std::calloc(length, sizeof(char)); assert(buf); std::fread(buf, sizeof(char), length, fp); // TODO: check fp w/ ferror() here return buf; } // TODO: search/replace other calls to stdd::free with this void utilSafeFree(void* mem) { assert(mem != nullptr); std::free(mem); mem = nullptr; }