Skip to content

Commit 99eea1d

Browse files
committed
refactor: delegate setvbuf buffer allocation to C stdio
1 parent af5aac6 commit 99eea1d

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

‎libxa_deinterleaver.hxx‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public:
3838
fprintf(stderr, "Error: Cannot read \"%s\". %s\n", inputPath.filename().string().c_str(), strerror(errno));
3939
return;
4040
}
41-
std::unique_ptr<char[]> stdiBuf(new char[STDIO_IOFBF_SIZE]);
42-
setvbuf(inputFile.get(), stdiBuf.get(), _IOFBF, STDIO_IOFBF_SIZE);
41+
setvbuf(inputFile.get(), nullptr, _IOFBF, STDIO_IOFBF_SIZE);
4342

4443
if (fread(buffer + FILENUM_OFFSET, 1, XA_DATA_SIZE, inputFile.get()) != XA_DATA_SIZE)
4544
{
@@ -111,12 +110,10 @@ public:
111110
if (!std::filesystem::exists(outputDir))
112111
std::filesystem::create_directories(outputDir);
113112

114-
std::unique_ptr<char[]> stdiBuf(new char[STDIO_IOFBF_SIZE]);
115-
std::unique_ptr<char[]> stdoBuf(new char[STDIO_IOFBF_SIZE]);
116-
117113
std::unique_ptr<FILE, decltype(&fclose)> inputFile(fopen(inputPath.string().c_str(), "rb"), &fclose);
118-
setvbuf(inputFile.get(), stdiBuf.get(), _IOFBF, STDIO_IOFBF_SIZE);
114+
setvbuf(inputFile.get(), nullptr, _IOFBF, STDIO_IOFBF_SIZE);
119115

116+
std::unique_ptr<char[]> stdoBuf(new char[STDIO_IOFBF_SIZE]);
120117
for (const FileInfo &entry : entries)
121118
{
122119
std::filesystem::path fileName = std::filesystem::u8path(entry.fileName);
@@ -205,7 +202,8 @@ private:
205202
int chunksRead = 0;
206203
bool eof = buffer[SUBMODE_OFFSET] & 0x80; // 0x80 = EOF_MASK
207204
bool silent = isSilent();
208-
do {
205+
for (;;)
206+
{
209207
//entry.endSec = currentSector;
210208
processedSectors[currentSector++] = true;
211209
//if (currentSector >= 42185) //
@@ -274,7 +272,7 @@ private:
274272
if (silent)
275273
silent = isSilent();
276274
}
277-
} while (true);
275+
}
278276

279277
END:
280278
const int nullSectors = entry.nullTrailing / entry.sectorChunk * entry.sectorStride + entry.nullTrailing;

‎xa-interleaver.cxx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ int main(int argc, char *argv[])
3434
fprintf(stderr, "Error: Cannot write \"%s\". %s\n", outputPath.string().c_str(), strerror(errno));
3535
return EXIT_FAILURE;
3636
}
37-
std::unique_ptr<char[]> stdoBuf(new char[1024 * 1024]);
38-
setvbuf(outputFile, stdoBuf.get(), _IOFBF, 1024 * 1024);
37+
setvbuf(outputFile, nullptr, _IOFBF, 1024 * 1024);
3938

4039
files.interleave(outputFile, sectorSize);
4140
fclose(outputFile);

0 commit comments

Comments
 (0)