Skip to content

Commit

Permalink
Common: fixes to BufferedStream
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed May 11, 2019
1 parent 1c0e202 commit d10a2d3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Common/util/bufferedstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ size_t BufferedStream::Write(const void *buffer, size_t size)
{
FileStream::Seek(_position, kSeekBegin);
auto sz = FileStream::Write(buffer, size);
if (_position == _end)
_end += sz;
_position += sz;
return sz;
}
Expand All @@ -114,19 +116,18 @@ int32_t BufferedStream::WriteByte(uint8_t val)

bool BufferedStream::Seek(soff_t offset, StreamSeek origin)
{
soff_t want_pos = -1;
switch(origin)
{
case StreamSeek::kSeekCurrent: _position = _position + offset; break;
case StreamSeek::kSeekBegin: _position = 0 + offset; break;
case StreamSeek::kSeekEnd: _position = _end + offset; break;
case StreamSeek::kSeekCurrent: want_pos = _position + offset; break;
case StreamSeek::kSeekBegin: want_pos = 0 + offset; break;
case StreamSeek::kSeekEnd: want_pos = _end + offset; break;
break;
}

// clamp
_position = std::min(_position, _end);
_position = std::max(_position, (soff_t)0);

return _position;
_position = std::min(std::max(want_pos, (soff_t)0), _end);
return _position == want_pos;
}

} // namespace Common
Expand Down

0 comments on commit d10a2d3

Please sign in to comment.