Skip to content

Commit

Permalink
Merge pull request #192 from dgelessus/fix_readline_when_no_trailing_…
Browse files Browse the repository at this point in the history
…newline

Fix `DS::Stream::readLine` for files without a trailing newline
  • Loading branch information
zrax committed Feb 23, 2024
2 parents b9f06e7 + 83b41c7 commit 78a71c9
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions streams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,19 @@ bool DS::Stream::readLine(void* buffer, size_t count)
DS_ASSERT(count >= 1);
char* outp = reinterpret_cast<char*>(buffer);
char* endp = outp + count - 1;
bool eof = false;

while (outp < endp) {
ssize_t nread = readBytes(outp, 1);
if (nread == 0) {
eof = true;
break;
}
char c = *outp++;
if (c == '\n')
break;
}
*outp = 0;
return !eof;
// Signal EOF if the loop terminated without reading anything into the buffer.
return outp != buffer;
}

ST::string DS::Stream::readString(size_t length, DS::StringType format)
Expand Down

0 comments on commit 78a71c9

Please sign in to comment.