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

@@ -168,11 +168,11 @@ struct ScriptFileChecksumCreator : FileScanner {
size_t len, size;
/* Open the file ... */
FILE *f = FioFOpenFile(filename, "rb", this->dir, &size);
if (f == nullptr) return false;
auto f = FioFOpenFile(filename, "rb", this->dir, &size);
if (!f.has_value()) return false;
/* ... calculate md5sum... */
while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, *f)) != 0 && size != 0) {
size -= len;
checksum.Append(buffer, len);
}
@@ -180,8 +180,6 @@ struct ScriptFileChecksumCreator : FileScanner {
MD5Hash tmp_md5sum;
checksum.Finish(tmp_md5sum);
FioFCloseFile(f);
/* ... and xor it to the overall md5sum. */
this->md5sum ^= tmp_md5sum;