diff --git a/src/nostalgia/core/userland/media.cpp b/src/nostalgia/core/userland/media.cpp index f900d20f3..edd7a03aa 100644 --- a/src/nostalgia/core/userland/media.cpp +++ b/src/nostalgia/core/userland/media.cpp @@ -6,25 +6,26 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include +#include + +#include #include "../media.hpp" namespace nostalgia::core { uint8_t *loadRom(const char *path) { - auto file = fopen(path, "r"); - if (file) { - fseek(file, 0, SEEK_END); - const auto size = ftell(file); - rewind(file); - auto buff = new uint8_t[size]; - fread(buff, size, 1, file); - fclose(file); - return buff; - } else { + std::ifstream file(path, std::ios::binary | std::ios::ate); + if (!file.good()) { + oxTrace("nostalgia::core::userland::loadRom") << "Read failed:" << path; return nullptr; } + + const std::size_t size = file.tellg(); + file.seekg(0, std::ios::beg); + auto buff = new uint8_t[size]; + file.read(reinterpret_cast(buff), size); + return buff; } void unloadRom(uint8_t *rom) {