Codechange: Replace all FILE * with FileHandle RAII class. (#12718)

This removes the need to manually ensure all files are closed.
This commit is contained in:
Peter Nelson
2024-09-16 08:45:26 +01:00
committed by GitHub
parent 3784a3d3d6
commit 908ee7292b
40 changed files with 368 additions and 442 deletions

View File

@@ -49,10 +49,8 @@ void CDECL StrgenFatalI(const std::string &msg)
LanguageStrings ReadRawLanguageStrings(const std::string &file)
{
size_t to_read;
FILE *fh = FioFOpenFile(file, "rb", GAME_DIR, &to_read);
if (fh == nullptr) return LanguageStrings();
FileCloser fhClose(fh);
auto fh = FioFOpenFile(file, "rb", GAME_DIR, &to_read);
if (!fh.has_value()) return LanguageStrings();
auto pos = file.rfind(PATHSEPCHAR);
if (pos == std::string::npos) return LanguageStrings();
@@ -64,7 +62,7 @@ LanguageStrings ReadRawLanguageStrings(const std::string &file)
LanguageStrings ret(langname.substr(0, langname.find('.')));
char buffer[2048];
while (to_read != 0 && fgets(buffer, sizeof(buffer), fh) != nullptr) {
while (to_read != 0 && fgets(buffer, sizeof(buffer), *fh) != nullptr) {
size_t len = strlen(buffer);
/* Remove trailing spaces/newlines from the string. */