1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-24 12:44:10 +01:00

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

@@ -194,13 +194,13 @@ void IniLoadFile::LoadFromDisk(const std::string &filename, Subdirectory subdir)
std::string comment;
size_t end;
FILE *in = this->OpenFile(filename, subdir, &end);
if (in == nullptr) return;
auto in = this->OpenFile(filename, subdir, &end);
if (!in.has_value()) return;
end += ftell(in);
end += ftell(*in);
/* for each line in the file */
while (static_cast<size_t>(ftell(in)) < end && fgets(buffer, sizeof(buffer), in)) {
while (static_cast<size_t>(ftell(*in)) < end && fgets(buffer, sizeof(buffer), *in)) {
char c, *s;
/* trim whitespace from the left side */
for (s = buffer; *s == ' ' || *s == '\t'; s++) {}
@@ -272,7 +272,5 @@ void IniLoadFile::LoadFromDisk(const std::string &filename, Subdirectory subdir)
}
this->comment = std::move(comment);
fclose(in);
}