Skip to content

Commit 636ee0f

Browse files
vpa1977SoapZA
authored andcommitted
s/t/bamtools_filter.cpp: simplify GetScriptContents().
Closes: #238
1 parent 1ce1d52 commit 636ee0f

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/toolkit/bamtools_filter.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -540,22 +540,18 @@ const std::string FilterTool::FilterToolPrivate::GetScriptContents()
540540
// read in entire script contents
541541
char buffer[1024];
542542
std::ostringstream docStream;
543-
while (true) {
544-
545-
// peek ahead, make sure there is data available
546-
char ch = fgetc(inFile);
547-
ungetc(ch, inFile);
548-
if (feof(inFile)) {
543+
while (!feof(inFile)) {
544+
// read next block of data
545+
const char* data = fgets(buffer, sizeof(buffer), inFile);
546+
if (!data) {
549547
break;
550548
}
551-
552-
// read next block of data
553-
if (fgets(buffer, 1024, inFile) == 0) {
549+
if (ferror(inFile)) {
554550
std::cerr << "bamtools filter ERROR: could not read script contents" << std::endl;
555-
return std::string();
551+
return {};
556552
}
557553

558-
docStream << buffer;
554+
docStream << data;
559555
}
560556

561557
// close script file

0 commit comments

Comments
 (0)