BIOS: Use fopen() wrapper from FileSystem

This commit is contained in:
Connor McLaughlin 2020-07-31 16:03:32 +10:00
parent 8b0c3f0dc8
commit 66e79091d3
1 changed files with 14 additions and 15 deletions

View File

@ -1,7 +1,9 @@
#include "bios.h"
#include "common/assert.h"
#include "common/file_system.h"
#include "common/log.h"
#include "common/md5_digest.h"
#include "common/windows_headers.h"
#include "cpu_disasm.h"
#include <cerrno>
Log_SetChannel(BIOS);
@ -57,33 +59,30 @@ std::optional<Image> LoadImageFromFile(std::string_view filename)
{
Image ret(BIOS_SIZE);
std::string filename_str(filename);
std::FILE* fp = std::fopen(filename_str.c_str(), "rb");
auto fp = FileSystem::OpenManagedCFile(filename_str.c_str(), "rb");
if (!fp)
{
Log_ErrorPrintf("Failed to open BIOS image '%s', errno=%d", filename_str.c_str(), errno);
return std::nullopt;
}
std::fseek(fp, 0, SEEK_END);
const u32 size = static_cast<u32>(std::ftell(fp));
std::fseek(fp, 0, SEEK_SET);
std::fseek(fp.get(), 0, SEEK_END);
const u32 size = static_cast<u32>(std::ftell(fp.get()));
std::fseek(fp.get(), 0, SEEK_SET);
if (size != BIOS_SIZE)
{
Log_ErrorPrintf("BIOS image '%s' mismatch, expecting %u bytes, got %u bytes", filename_str.c_str(), BIOS_SIZE,
size);
std::fclose(fp);
return std::nullopt;
}
if (std::fread(ret.data(), 1, ret.size(), fp) != ret.size())
if (std::fread(ret.data(), 1, ret.size(), fp.get()) != ret.size())
{
Log_ErrorPrintf("Failed to read BIOS image '%s'", filename_str.c_str());
std::fclose(fp);
return std::nullopt;
}
std::fclose(fp);
return ret;
}