mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-29 06:17:48 +00:00
Only open files when necessary
This commit is contained in:
@@ -9,6 +9,11 @@
|
||||
|
||||
#include "extern/err.h"
|
||||
|
||||
FILE *outputFile;
|
||||
FILE *overlayFile;
|
||||
FILE *symFile;
|
||||
FILE *mapFile;
|
||||
|
||||
struct SortedSection {
|
||||
struct Section const *section;
|
||||
struct SortedSection *next;
|
||||
@@ -158,6 +163,9 @@ static void writeBank(struct SortedSection *bankSections, uint16_t baseOffset,
|
||||
*/
|
||||
static void writeROM(void)
|
||||
{
|
||||
outputFile = openFile(outputFileName, "wb");
|
||||
overlayFile = openFile(overlayFileName, "rb");
|
||||
|
||||
checkOverlay();
|
||||
|
||||
if (outputFile) {
|
||||
@@ -177,6 +185,9 @@ static void writeROM(void)
|
||||
funlockfile(overlayFile);
|
||||
funlockfile(outputFile);
|
||||
}
|
||||
|
||||
closeFile(outputFile);
|
||||
closeFile(overlayFile);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -310,7 +321,7 @@ static void writeMapBank(struct SortedSections const *sectList,
|
||||
*/
|
||||
static void writeSymAndMap(void)
|
||||
{
|
||||
if (!symFile && !mapFile)
|
||||
if (!symFileName && !mapFileName)
|
||||
return;
|
||||
|
||||
enum SectionType typeMap[SECTTYPE_INVALID] = {
|
||||
@@ -324,8 +335,12 @@ static void writeSymAndMap(void)
|
||||
SECTTYPE_HRAM
|
||||
};
|
||||
|
||||
if (symFile)
|
||||
symFile = openFile(symFileName, "w");
|
||||
mapFile = openFile(mapFileName, "w");
|
||||
|
||||
if (symFileName) {
|
||||
fputs("; File generated by rgblink\n", symFile);
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < SECTTYPE_INVALID; i++) {
|
||||
enum SectionType type = typeMap[i];
|
||||
@@ -339,6 +354,9 @@ static void writeSymAndMap(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closeFile(symFile);
|
||||
closeFile(mapFile);
|
||||
}
|
||||
|
||||
static void cleanupSections(struct SortedSection *section)
|
||||
|
||||
Reference in New Issue
Block a user