dosgame1/util/Files.cpp

28 lines
543 B
C++

#include "Files.h"
#include <cstdio>
size_t Files::allocateBufferAndLoadFromFile(const char *path, void **bufferPointer) {
auto fp = fopen(path, "rb");
if (!fp) {
*bufferPointer = nullptr;
return 0;
}
fseek(fp, 0, SEEK_END);
size_t len = ftell(fp);
fseek(fp, 0, SEEK_SET);
auto data = new unsigned char[len];
fread(data, 1, len, fp);
fclose(fp);
*bufferPointer = data;
return len;
}
void Files::deleteBuffer(void *buffer) {
delete[] static_cast<unsigned char*>(buffer);
}