mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Use a Defer struct to close files and restore lexer state with RAII (#1379)
This commit is contained in:
@@ -473,7 +473,6 @@ static void readAssertion(
|
||||
|
||||
void obj_ReadFile(char const *fileName, unsigned int fileID) {
|
||||
FILE *file;
|
||||
|
||||
if (strcmp(fileName, "-")) {
|
||||
file = fopen(fileName, "rb");
|
||||
} else {
|
||||
@@ -482,6 +481,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
|
||||
}
|
||||
if (!file)
|
||||
err("Failed to open file \"%s\"", fileName);
|
||||
Defer closeFile{[&] { fclose(file); }};
|
||||
|
||||
// First, check if the object is a RGBDS object or a SDCC one. If the first byte is 'R',
|
||||
// we'll assume it's a RGBDS object file, and otherwise, that it's a SDCC object file.
|
||||
@@ -630,8 +630,6 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
void obj_CheckAssertions() {
|
||||
|
||||
Reference in New Issue
Block a user