BIOS: Use fopen() wrapper from FileSystem
This commit is contained in:
parent
8b0c3f0dc8
commit
66e79091d3
|
@ -1,7 +1,9 @@
|
||||||
#include "bios.h"
|
#include "bios.h"
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
|
#include "common/file_system.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/md5_digest.h"
|
#include "common/md5_digest.h"
|
||||||
|
#include "common/windows_headers.h"
|
||||||
#include "cpu_disasm.h"
|
#include "cpu_disasm.h"
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
Log_SetChannel(BIOS);
|
Log_SetChannel(BIOS);
|
||||||
|
@ -57,33 +59,30 @@ std::optional<Image> LoadImageFromFile(std::string_view filename)
|
||||||
{
|
{
|
||||||
Image ret(BIOS_SIZE);
|
Image ret(BIOS_SIZE);
|
||||||
std::string filename_str(filename);
|
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)
|
if (!fp)
|
||||||
{
|
{
|
||||||
Log_ErrorPrintf("Failed to open BIOS image '%s', errno=%d", filename_str.c_str(), errno);
|
Log_ErrorPrintf("Failed to open BIOS image '%s', errno=%d", filename_str.c_str(), errno);
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::fseek(fp, 0, SEEK_END);
|
std::fseek(fp.get(), 0, SEEK_END);
|
||||||
const u32 size = static_cast<u32>(std::ftell(fp));
|
const u32 size = static_cast<u32>(std::ftell(fp.get()));
|
||||||
std::fseek(fp, 0, SEEK_SET);
|
std::fseek(fp.get(), 0, SEEK_SET);
|
||||||
|
|
||||||
if (size != BIOS_SIZE)
|
if (size != BIOS_SIZE)
|
||||||
{
|
{
|
||||||
Log_ErrorPrintf("BIOS image '%s' mismatch, expecting %u bytes, got %u bytes", filename_str.c_str(), BIOS_SIZE,
|
Log_ErrorPrintf("BIOS image '%s' mismatch, expecting %u bytes, got %u bytes", filename_str.c_str(), BIOS_SIZE,
|
||||||
size);
|
size);
|
||||||
std::fclose(fp);
|
|
||||||
return std::nullopt;
|
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());
|
Log_ErrorPrintf("Failed to read BIOS image '%s'", filename_str.c_str());
|
||||||
std::fclose(fp);
|
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::fclose(fp);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue