From f64412ebfe95a220f6138d676c418d384080fed3 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Fri, 14 Sep 2018 05:30:22 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Add=20debug=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fileReader.c | 12 +++++++++--- src/utils/fileUtilities.c | 9 ++++++--- src/utils/fileUtilities.h | 6 +++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/fileReader.c b/src/fileReader.c index 582d998..9557bf7 100644 --- a/src/fileReader.c +++ b/src/fileReader.c @@ -52,9 +52,15 @@ void getBytes(uint8_t* buffer, unsigned long numBytes, bool isLast) { remainingBytes -= availableBytes; //If we've reached end of file, close file and open next file - //Unless we've reached the end, in that case don't open next file in case we've reached the end of the last disk - if (!isLast && file.offset == file.size) { - openNextFile(); + if (file.offset == file.size) { + closeCurrentFile(); + //Unless we've reached the end, in that case don't open next file in case we've reached the end of the last disk + if (!isLast) { + openNextFile(); + } else if (remainingBytes > 0) { + fprintf(stderr, "Reached end of last disk but had to read %lu more bytes.\n", remainingBytes); + errorAndExit(); + } } } } diff --git a/src/utils/fileUtilities.c b/src/utils/fileUtilities.c index 77d6882..5a342f7 100644 --- a/src/utils/fileUtilities.c +++ b/src/utils/fileUtilities.c @@ -32,15 +32,18 @@ void skipBytes(long numBytes) { } -//Closes the currently opened file and opens the next file at its beginning. -void openNextFile() { +//Closes the currently opened file +void closeCurrentFile() { const int closeResult = fclose(file.filePointer); if (closeResult != 0) { fprintf(stderr, "Could not close file: %s\n", strerror(errno)); exit(1); } +} - //Open next file + +//Opens the next file at its beginning. +void openNextFile() { const size_t fileNameLength = strlen(file.name); //We need to transfer carry if necessary (e.g. .z09 to .z10), otherwise just increase last digit if (file.name[fileNameLength - 1] == '9') { diff --git a/src/utils/fileUtilities.h b/src/utils/fileUtilities.h index 2f8508d..bb9cd75 100644 --- a/src/utils/fileUtilities.h +++ b/src/utils/fileUtilities.h @@ -21,5 +21,9 @@ void readBytesIntoBuffer(uint8_t* buffer, long numBytes); void skipBytes(long numBytes); -//Closes the currently opened file and opens the next file at its beginning. +//Closes the currently opened file +void closeCurrentFile(); + + +//Opens the next file at its beginning. void openNextFile();