Skip to content

Commit

Permalink
Use std::streamoff for BinaryIO offset vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauler125 committed Dec 23, 2024
1 parent 092a81a commit 234bfb0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/utils/binaryio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,25 @@ std::streampos BinaryIO::TellPut()
// Input : offset -
// way -
//-----------------------------------------------------------------------------
void BinaryIO::SeekGet(const std::streampos offset, const std::ios_base::seekdir way)
void BinaryIO::SeekGet(const std::streamoff offset, const std::ios_base::seekdir way)
{
assert(IsReadMode());
m_stream.seekg(offset, way);
}
void BinaryIO::SeekPut(const std::streampos offset, const std::ios_base::seekdir way)
void BinaryIO::SeekPut(const std::streamoff offset, const std::ios_base::seekdir way)
{
assert(IsWriteMode());

m_stream.seekp(offset, way);
const std::streampos newOffset = m_stream.tellp();
const std::streamoff newOffset = m_stream.tellp();

// seekp writes padding when we go beyond eof, therefore we should update
// the size in case this happens.
if (newOffset > m_size)
m_size = newOffset;

}
void BinaryIO::Seek(const std::streampos offset, const std::ios_base::seekdir way)
void BinaryIO::Seek(const std::streamoff offset, const std::ios_base::seekdir way)
{
if (IsReadMode())
SeekGet(offset, way);
Expand All @@ -157,7 +157,7 @@ const std::filebuf* BinaryIO::GetData() const
// Purpose: returns the data size
// Output : std::streampos
//-----------------------------------------------------------------------------
const std::streampos BinaryIO::GetSize() const
const std::streamoff BinaryIO::GetSize() const
{
return m_size;
}
Expand Down
10 changes: 5 additions & 5 deletions src/utils/binaryio.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class BinaryIO
std::streampos TellGet();
std::streampos TellPut();

void SeekGet(const std::streampos offset, const std::ios_base::seekdir way = std::ios::beg);
void SeekPut(const std::streampos offset, const std::ios_base::seekdir way = std::ios::beg);
void Seek(const std::streampos offset, const std::ios_base::seekdir way = std::ios::beg);
void SeekGet(const std::streamoff offset, const std::ios_base::seekdir way = std::ios::beg);
void SeekPut(const std::streamoff offset, const std::ios_base::seekdir way = std::ios::beg);
void Seek(const std::streamoff offset, const std::ios_base::seekdir way = std::ios::beg);

const std::filebuf* GetData() const;
const std::streampos GetSize() const;
const std::streamoff GetSize() const;

bool IsReadMode() const;
bool IsWriteMode() const;
Expand Down Expand Up @@ -110,7 +110,7 @@ class BinaryIO

private:
std::fstream m_stream; // I/O stream.
std::streampos m_size; // File size.
std::streamoff m_size; // File size.
std::ios_base::openmode m_flags; // Stream flags.
Mode_e m_mode; // Stream mode.
};

0 comments on commit 234bfb0

Please sign in to comment.