Only open files when necessary

This commit is contained in:
ISSOtm
2019-10-11 09:04:50 +02:00
parent 8a59994c0d
commit bf75971a3a
6 changed files with 79 additions and 54 deletions

View File

@@ -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)