From a3b90e486eee8dd4542447eb816e3e17c7428b01 Mon Sep 17 00:00:00 2001 From: Vladimir Petko Date: Tue, 9 Jul 2024 15:16:12 +1200 Subject: [PATCH] s/t/bamtools_filter.cpp: simplify GetScriptContents(). --- src/toolkit/bamtools_filter.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/toolkit/bamtools_filter.cpp b/src/toolkit/bamtools_filter.cpp index bc4a3db..b197aad 100644 --- a/src/toolkit/bamtools_filter.cpp +++ b/src/toolkit/bamtools_filter.cpp @@ -540,22 +540,18 @@ const std::string FilterTool::FilterToolPrivate::GetScriptContents() // read in entire script contents char buffer[1024]; std::ostringstream docStream; - while (true) { - - // peek ahead, make sure there is data available - char ch = fgetc(inFile); - ungetc(ch, inFile); - if (feof(inFile)) { + while (!feof(inFile)) { + // read next block of data + char *data = fgets(buffer, 1024, inFile); + if (data == 0) { break; } - - // read next block of data - if (fgets(buffer, 1024, inFile) == 0) { + if (ferror(inFile)) { std::cerr << "bamtools filter ERROR: could not read script contents" << std::endl; return std::string(); } - docStream << buffer; + docStream << data; } // close script file