Skip to content

Commit

Permalink
[Ref] FileReader: Remove FileReader::off_t and replace it with FileRe…
Browse files Browse the repository at this point in the history
…ader::pos_type. This avoids confusion with POSIX off_t which is a signed type, while FileReader::off_t was an unsigned type just like FileReader::pos_type.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@19728 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
manxorist committed Sep 20, 2023
1 parent ec2abbc commit 724875e
Show file tree
Hide file tree
Showing 37 changed files with 109 additions and 109 deletions.
7 changes: 3 additions & 4 deletions common/FileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ class FileReader
public:

using pos_type = typename traits_type::pos_type;
using off_t = pos_type;

using data_type = typename traits_type::data_type;
using ref_data_type = typename traits_type::ref_data_type;
Expand Down Expand Up @@ -382,19 +381,19 @@ class FileReader
using ChunkList = mpt::IO::FileReader::ChunkList<T, FileReader>;

template<typename T>
Item<T> ReadNextChunk(off_t alignment)
Item<T> ReadNextChunk(pos_type alignment)
{
return mpt::IO::FileReader::ReadNextChunk<T, FileReader>(*this, alignment);
}

template<typename T>
ChunkList<T> ReadChunks(off_t alignment)
ChunkList<T> ReadChunks(pos_type alignment)
{
return mpt::IO::FileReader::ReadChunks<T, FileReader>(*this, alignment);
}

template<typename T>
ChunkList<T> ReadChunksUntil(off_t alignment, decltype(T().GetID()) stopAtID)
ChunkList<T> ReadChunksUntil(pos_type alignment, decltype(T().GetID()) stopAtID)
{
return mpt::IO::FileReader::ReadChunksUntil<T, FileReader>(*this, alignment, stopAtID);
}
Expand Down
7 changes: 4 additions & 3 deletions soundlib/BitReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ OPENMPT_NAMESPACE_BEGIN
class BitReader : private FileReader
{
protected:
off_t m_bufPos = 0, m_bufSize = 0;
pos_type m_bufPos = 0;
pos_type m_bufSize = 0;
uint32 bitBuf = 0; // Current bit buffer
int m_bitNum = 0; // Currently available number of bits
std::byte buffer[mpt::IO::BUFFERSIZE_TINY]{};
Expand All @@ -43,12 +44,12 @@ class BitReader : private FileReader
BitReader(const FileCursor &other) : FileReader(other) { }
BitReader(FileCursor &&other) : FileReader(std::move(other)) { }

off_t GetLength() const
pos_type GetLength() const
{
return FileReader::GetLength();
}

off_t GetPosition() const
pos_type GetPosition() const
{
return FileReader::GetPosition() - m_bufSize + m_bufPos;
}
Expand Down
2 changes: 1 addition & 1 deletion soundlib/ContainerPP20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ bool UnpackPP20(std::vector<ContainerItem> &containerItems, FileReader &file, Co
containerItems.back().data_cache = std::make_unique<std::vector<char> >();
std::vector<char> & unpackedData = *(containerItems.back().data_cache);

FileReader::off_t length = file.GetLength();
FileReader::pos_type length = file.GetLength();
if(!mpt::in_range<uint32>(length)) return false;
// Length word must be aligned
if((length % 2u) != 0)
Expand Down
2 changes: 1 addition & 1 deletion soundlib/Load_669.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool CSoundFile::Read669(FileReader &file, ModLoadingFlags loadFlags)
return true;
}

if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(fileHeader))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(fileHeader))))
{
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions soundlib/Load_amf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ bool CSoundFile::ReadAMF_Asylum(FileReader &file, ModLoadingFlags loadFlags)
{
return false;
}
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(fileHeader))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(fileHeader))))
{
return false;
}
Expand Down Expand Up @@ -644,7 +644,7 @@ bool CSoundFile::ReadAMF_DSMI(FileReader &file, ModLoadingFlags loadFlags)
// Setup Order List
Order().resize(fileHeader.numOrders);
std::vector<uint16> patternLength;
const FileReader::off_t trackStartPos = file.GetPosition() + (fileSignature.version >= 14 ? 2 : 0);
const FileReader::pos_type trackStartPos = file.GetPosition() + (fileSignature.version >= 14 ? 2 : 0);
if(fileSignature.version >= 14)
{
patternLength.resize(fileHeader.numOrders);
Expand Down
4 changes: 2 additions & 2 deletions soundlib/Load_ams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ bool CSoundFile::ReadAMS(FileReader &file, ModLoadingFlags loadFlags)
{
return false;
}
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(fileHeader))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(fileHeader))))
{
return false;
}
Expand Down Expand Up @@ -765,7 +765,7 @@ bool CSoundFile::ReadAMS2(FileReader &file, ModLoadingFlags loadFlags)
{
return false;
}
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(fileHeader))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(fileHeader))))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion soundlib/Load_c67.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ bool CSoundFile::ReadC67(FileReader &file, ModLoadingFlags loadFlags)
return true;
}

if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(fileHeader))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(fileHeader))))
{
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions soundlib/Load_dsym.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static std::vector<std::byte> DecompressDSymLZW(FileReader &file, uint32 size)
MPT_ASSERT(output.size() == size);

// Align length to 4 bytes
file.Seek(startPos + ((bitFile.GetPosition() - startPos + 3u) & ~FileReader::off_t(3)));
file.Seek(startPos + ((bitFile.GetPosition() - startPos + 3u) & ~FileReader::pos_type(3)));
return output;
}

Expand Down Expand Up @@ -183,7 +183,7 @@ static std::vector<std::byte> DecompressDSymSigmaDelta(FileReader &file, uint32
}

// Align length to 4 bytes
file.Seek(startPos + ((bitFile.GetPosition() - startPos + 3u) & ~FileReader::off_t(3)));
file.Seek(startPos + ((bitFile.GetPosition() - startPos + 3u) & ~FileReader::pos_type(3)));
return output;
}

Expand Down Expand Up @@ -230,7 +230,7 @@ bool CSoundFile::ReadDSym(FileReader &file, ModLoadingFlags loadFlags)
file.Rewind();
if(!file.ReadStruct(fileHeader) || !fileHeader.Validate())
return false;
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(fileHeader.GetHeaderMinimumAdditionalSize())))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(fileHeader.GetHeaderMinimumAdditionalSize())))
return false;
if(loadFlags == onlyVerifyHeader)
return true;
Expand Down
2 changes: 1 addition & 1 deletion soundlib/Load_far.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ bool CSoundFile::ReadFAR(FileReader &file, ModLoadingFlags loadFlags)
{
return false;
}
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(fileHeader))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(fileHeader))))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion soundlib/Load_fmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool CSoundFile::ReadFMT(FileReader &file, ModLoadingFlags loadFlags)
return false;
if(!ValidateHeader(fileHeader))
return false;
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(fileHeader))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(fileHeader))))
return false;
if(loadFlags == onlyVerifyHeader)
return true;
Expand Down
4 changes: 2 additions & 2 deletions soundlib/Load_gt2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ bool CSoundFile::ReadGTK(FileReader &file, ModLoadingFlags loadFlags)
return false;
if(!fileHeader.Validate())
return false;
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(fileHeader.GetHeaderMinimumAdditionalSize())))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(fileHeader.GetHeaderMinimumAdditionalSize())))
return false;
if(loadFlags == onlyVerifyHeader)
return true;
Expand Down Expand Up @@ -1202,7 +1202,7 @@ bool CSoundFile::ReadGT2(FileReader &file, ModLoadingFlags loadFlags)
return false;
if(!fileHeader.Validate())
return false;
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(fileHeader.GetHeaderMinimumAdditionalSize())))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(fileHeader.GetHeaderMinimumAdditionalSize())))
return false;
if(loadFlags == onlyVerifyHeader)
return true;
Expand Down
2 changes: 1 addition & 1 deletion soundlib/Load_imf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ bool CSoundFile::ReadIMF(FileReader &file, ModLoadingFlags loadFlags)
{
return false;
}
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(fileHeader))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(fileHeader))))
{
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions soundlib/Load_it.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ size_t CSoundFile::ITInstrToMPT(FileReader &file, ModInstrument &ins, uint16 trk
}
} else
{
const FileReader::off_t offset = file.GetPosition();
const FileReader::pos_type offset = file.GetPosition();

// Try loading extended instrument... instSize will differ between normal and extended instruments.
ITInstrumentEx instrumentHeader;
Expand Down Expand Up @@ -421,7 +421,7 @@ bool CSoundFile::ReadIT(FileReader &file, ModLoadingFlags loadFlags)
{
return false;
}
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(fileHeader))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(fileHeader))))
{
return false;
}
Expand Down Expand Up @@ -776,7 +776,7 @@ bool CSoundFile::ReadIT(FileReader &file, ModLoadingFlags loadFlags)
// In order to properly compute the position, in file, of eventual extended settings
// such as "attack" we need to keep the "real" size of the last sample as those extra
// setting will follow this sample in the file
FileReader::off_t lastSampleOffset = 0;
FileReader::pos_type lastSampleOffset = 0;
if(fileHeader.smpnum > 0)
{
lastSampleOffset = smpPos[fileHeader.smpnum - 1] + sizeof(ITSample);
Expand Down
2 changes: 1 addition & 1 deletion soundlib/Load_itp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ bool CSoundFile::ReadITP(FileReader &file, ModLoadingFlags loadFlags)
{
return false;
}
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(hdr))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(hdr))))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion soundlib/Load_med.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ bool CSoundFile::ReadMED(FileReader &file, ModLoadingFlags loadFlags)
return false;
if(!ValidateHeader(fileHeader))
return false;
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(fileHeader))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(fileHeader))))
return false;
if(loadFlags == onlyVerifyHeader)
return true;
Expand Down
22 changes: 11 additions & 11 deletions soundlib/Load_mo3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,11 @@ static int VorbisfileFilereaderSeek(void *datasource, ogg_int64_t offset, int wh
switch(whence)
{
case SEEK_SET:
if(!mpt::in_range<FileReader::off_t>(offset))
if(!mpt::in_range<FileReader::pos_type>(offset))
{
return -1;
}
return file.Seek(mpt::saturate_cast<FileReader::off_t>(offset)) ? 0 : -1;
return file.Seek(mpt::saturate_cast<FileReader::pos_type>(offset)) ? 0 : -1;

case SEEK_CUR:
if(offset < 0)
Expand All @@ -680,31 +680,31 @@ static int VorbisfileFilereaderSeek(void *datasource, ogg_int64_t offset, int wh
{
return -1;
}
if(!mpt::in_range<FileReader::off_t>(0 - offset))
if(!mpt::in_range<FileReader::pos_type>(0 - offset))
{
return -1;
}
return file.SkipBack(mpt::saturate_cast<FileReader::off_t>(0 - offset)) ? 0 : -1;
return file.SkipBack(mpt::saturate_cast<FileReader::pos_type>(0 - offset)) ? 0 : -1;
} else
{
if(!mpt::in_range<FileReader::off_t>(offset))
if(!mpt::in_range<FileReader::pos_type>(offset))
{
return -1;
}
return file.Skip(mpt::saturate_cast<FileReader::off_t>(offset)) ? 0 : -1;
return file.Skip(mpt::saturate_cast<FileReader::pos_type>(offset)) ? 0 : -1;
}
break;

case SEEK_END:
if(!mpt::in_range<FileReader::off_t>(offset))
if(!mpt::in_range<FileReader::pos_type>(offset))
{
return -1;
}
if(!mpt::in_range<FileReader::off_t>(file.GetLength() + offset))
if(!mpt::in_range<FileReader::pos_type>(file.GetLength() + offset))
{
return -1;
}
return file.Seek(mpt::saturate_cast<FileReader::off_t>(file.GetLength() + offset)) ? 0 : -1;
return file.Seek(mpt::saturate_cast<FileReader::pos_type>(file.GetLength() + offset)) ? 0 : -1;

default:
return -1;
Expand All @@ -714,7 +714,7 @@ static int VorbisfileFilereaderSeek(void *datasource, ogg_int64_t offset, int wh
static long VorbisfileFilereaderTell(void *datasource)
{
FileReader &file = *mpt::void_ptr<FileReader>(datasource);
FileReader::off_t result = file.GetPosition();
FileReader::pos_type result = file.GetPosition();
if(!mpt::in_range<long>(result))
{
return -1;
Expand Down Expand Up @@ -1790,7 +1790,7 @@ bool CSoundFile::ReadMO3(FileReader &file, ModLoadingFlags loadFlags)
cwtv = chunk.ReadUint16LE();
break;
case MOD_TYPE_XM:
chunk.ReadString<mpt::String::spacePadded>(madeWithTracker, mpt::Charset::CP437, std::min(FileReader::off_t(32), chunk.GetLength()));
chunk.ReadString<mpt::String::spacePadded>(madeWithTracker, mpt::Charset::CP437, std::min(FileReader::pos_type(32), chunk.GetLength()));
break;
case MOD_TYPE_MTM:
{
Expand Down
4 changes: 2 additions & 2 deletions soundlib/Load_mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ bool CSoundFile::ReadMOD(FileReader &file, ModLoadingFlags loadFlags)
// On the other hand, the loop points in Purple Motions's SOUL-O-M.MOD are completely broken and shouldn't be treated like this.
// As it was most likely written in Scream Tracker, it has empty sample slots with a default volume of 64, which we use for
// rejecting this quirk for that file.
FileReader::off_t nextSample = file.GetPosition() + sampleIO.CalculateEncodedSize(sample.nLength);
FileReader::pos_type nextSample = file.GetPosition() + sampleIO.CalculateEncodedSize(sample.nLength);
if(isMdKd && onlyAmigaNotes && !hasEmptySampleWithVolume)
sample.nLength = std::max(sample.nLength, sample.nLoopEnd);

Expand Down Expand Up @@ -1611,7 +1611,7 @@ bool CSoundFile::ReadM15(FileReader &file, ModLoadingFlags loadFlags)
// Setup channel pan positions and volume
SetupMODPanning();

FileReader::off_t patOffset = file.GetPosition();
FileReader::pos_type patOffset = file.GetPosition();

// Scan patterns to identify Ultimate Soundtracker modules.
uint32 illegalBytes = 0, totalNumDxx = 0;
Expand Down
2 changes: 1 addition & 1 deletion soundlib/Load_mt2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ bool CSoundFile::ReadMT2(FileReader &file, ModLoadingFlags loadFlags)
{
return false;
}
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(fileHeader))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(fileHeader))))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion soundlib/Load_mtm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ bool CSoundFile::ReadMTM(FileReader &file, ModLoadingFlags loadFlags)
{
return false;
}
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(fileHeader))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(fileHeader))))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion soundlib/Load_mus_km.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ bool CSoundFile::ReadMUS_KM(FileReader &file, ModLoadingFlags loadFlags)
return false;
if(!ValidateHeader(fileHeader))
return false;
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(fileHeader))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(fileHeader))))
return false;
if(loadFlags == onlyVerifyHeader)
return true;
Expand Down
2 changes: 1 addition & 1 deletion soundlib/Load_plm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ bool CSoundFile::ReadPLM(FileReader &file, ModLoadingFlags loadFlags)
{
return false;
}
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(fileHeader))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(fileHeader))))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion soundlib/Load_ptm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ bool CSoundFile::ReadPTM(FileReader &file, ModLoadingFlags loadFlags)
{
return false;
}
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(fileHeader))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(fileHeader))))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion soundlib/Load_s3m.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ bool CSoundFile::ReadS3M(FileReader &file, ModLoadingFlags loadFlags)
{
return false;
}
if(!file.CanRead(mpt::saturate_cast<FileReader::off_t>(GetHeaderMinimumAdditionalSize(fileHeader))))
if(!file.CanRead(mpt::saturate_cast<FileReader::pos_type>(GetHeaderMinimumAdditionalSize(fileHeader))))
{
return false;
}
Expand Down
Loading

0 comments on commit 724875e

Please sign in to comment.