2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 15:44:56 +00:00

General: Make use of FopenUnique where applicable

Migrates to the hecl Fopen variant that automatically closes its
contained file handle if it goes out of scope.
This commit is contained in:
Lioncash
2019-08-26 14:37:19 -04:00
parent f48ebefa84
commit 1d3062b33f
9 changed files with 60 additions and 73 deletions

View File

@@ -39,10 +39,10 @@ kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot sl
return {};
path += fmt::format(fmt("/MemoryCard{:c}.USA.raw"), slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
FILE* fp = hecl::Fopen(path.c_str(), "wb");
if (!fp)
const auto fp = hecl::FopenUnique(path.c_str(), "wb");
if (fp == nullptr) {
return {};
fclose(fp);
}
return path;
}

View File

@@ -29,10 +29,10 @@ kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot sl
return {};
path += fmt::format(fmt("/MemoryCard{:c}.USA.raw"), slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
FILE* fp = hecl::Fopen(path.c_str(), "wb");
if (!fp)
const auto fp = hecl::FopenUnique(path.c_str(), "wb");
if (fp == nullptr) {
return {};
fclose(fp);
}
return path;
}

View File

@@ -100,10 +100,10 @@ kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot sl
path += fmt::format(fmt(_SYS_STR("/MemoryCard{}.USA.raw")),
slot == kabufuda::ECardSlot::SlotA ? _SYS_STR('A') : _SYS_STR('B'));
FILE* fp = hecl::Fopen(path.c_str(), _SYS_STR("wb"));
if (!fp)
const auto fp = hecl::FopenUnique(path.c_str(), _SYS_STR("wb"));
if (fp == nullptr) {
return {};
fclose(fp);
}
return path;
}