Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DS::Stream::readLine for files without a trailing newline #192

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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