2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 21:07:42 +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

@@ -613,12 +613,13 @@ struct SpecMP1 : SpecBase {
} else if (hecl::IsPathPNG(path)) {
return {SBIG('TXTR'), path.hash().val32()};
} else if (hecl::IsPathYAML(path)) {
FILE* fp = hecl::Fopen(path.getAbsolutePath().data(), _SYS_STR("r"));
if (!fp)
auto fp = hecl::FopenUnique(path.getAbsolutePath().data(), _SYS_STR("r"));
if (fp == nullptr) {
return {};
}
athena::io::YAMLDocReader reader;
yaml_parser_set_input_file(reader.getParser(), fp);
yaml_parser_set_input_file(reader.getParser(), fp.get());
urde::SObjectTag resTag;
if (reader.ClassTypeOperation([&](const char* className) -> bool {
@@ -700,10 +701,9 @@ struct SpecMP1 : SpecBase {
return false;
})) {
resTag.id = path.hash().val32();
fclose(fp);
fp.reset();
return resTag;
}
fclose(fp);
}
return {};
}