diff --git a/taglib/ape/apefile.cpp b/taglib/ape/apefile.cpp index cb652242..24158cf3 100644 --- a/taglib/ape/apefile.cpp +++ b/taglib/ape/apefile.cpp @@ -66,10 +66,10 @@ public: delete properties; } - long APELocation; + offset_t APELocation; uint APESize; - long ID3v1Location; + offset_t ID3v1Location; TagUnion tag; @@ -272,7 +272,7 @@ void APE::File::read(bool readProperties, Properties::ReadStyle /* propertiesSty } } -long APE::File::findAPE() +offset_t APE::File::findAPE() { if(!isValid()) return -1; @@ -282,7 +282,7 @@ long APE::File::findAPE() else seek(-32, End); - long p = tell(); + offset_t p = tell(); if(readBlock(8) == APE::Tag::fileIdentifier()) return p; @@ -290,13 +290,13 @@ long APE::File::findAPE() return -1; } -long APE::File::findID3v1() +offset_t APE::File::findID3v1() { if(!isValid()) return -1; seek(-128, End); - long p = tell(); + offset_t p = tell(); if(readBlock(3) == ID3v1::Tag::fileIdentifier()) return p; diff --git a/taglib/ape/apefile.h b/taglib/ape/apefile.h index 8b187f6a..ec55207f 100644 --- a/taglib/ape/apefile.h +++ b/taglib/ape/apefile.h @@ -189,8 +189,8 @@ namespace TagLib { void read(bool readProperties, Properties::ReadStyle propertiesStyle); void scan(); - long findID3v1(); - long findAPE(); + offset_t findID3v1(); + offset_t findAPE(); class FilePrivate; FilePrivate *d; diff --git a/taglib/ape/apeproperties.cpp b/taglib/ape/apeproperties.cpp index b4fcec6a..c99996f0 100644 --- a/taglib/ape/apeproperties.cpp +++ b/taglib/ape/apeproperties.cpp @@ -39,7 +39,7 @@ using namespace TagLib; class APE::Properties::PropertiesPrivate { public: - PropertiesPrivate(File *file, long streamLength) : + PropertiesPrivate(File *file, offset_t streamLength) : length(0), bitrate(0), sampleRate(0), @@ -58,7 +58,7 @@ public: int bitsPerSample; uint sampleFrames; File *file; - long streamLength; + offset_t streamLength; }; //////////////////////////////////////////////////////////////////////////////// @@ -119,7 +119,7 @@ TagLib::uint APE::Properties::sampleFrames() const void APE::Properties::read() { // First we are searching the descriptor - long offset = findDescriptor(); + offset_t offset = findDescriptor(); if(offset < 0) return; @@ -138,9 +138,9 @@ void APE::Properties::read() } } -long APE::Properties::findDescriptor() +offset_t APE::Properties::findDescriptor() { - long ID3v2Location = findID3v2(); + offset_t ID3v2Location = findID3v2(); long ID3v2OriginalSize = 0; bool hasID3v2 = false; if(ID3v2Location >= 0) { @@ -150,7 +150,7 @@ long APE::Properties::findDescriptor() hasID3v2 = true; } - long offset = 0; + offset_t offset = 0; if(hasID3v2) offset = d->file->find("MAC ", ID3v2Location + ID3v2OriginalSize); else @@ -164,7 +164,7 @@ long APE::Properties::findDescriptor() return offset; } -long APE::Properties::findID3v2() +offset_t APE::Properties::findID3v2() { if(!d->file->isValid()) return -1; @@ -201,7 +201,7 @@ void APE::Properties::analyzeCurrent() uint finalFrameBlocks = header.mid(8, 4).toUInt(false); d->sampleFrames = totalFrames > 0 ? (totalFrames - 1) * blocksPerFrame + finalFrameBlocks : 0; d->length = d->sampleRate > 0 ? d->sampleFrames / d->sampleRate : 0; - d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0; + d->bitrate = d->length > 0 ? static_cast(d->streamLength * 8L / d->length / 1000) : 0; } void APE::Properties::analyzeOld() @@ -226,6 +226,6 @@ void APE::Properties::analyzeOld() uint finalFrameBlocks = header.mid(22, 4).toUInt(false); uint totalBlocks = totalFrames > 0 ? (totalFrames - 1) * blocksPerFrame + finalFrameBlocks : 0; d->length = totalBlocks / d->sampleRate; - d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0; + d->bitrate = d->length > 0 ? static_cast(d->streamLength * 8L / d->length / 1000) : 0; } diff --git a/taglib/ape/apeproperties.h b/taglib/ape/apeproperties.h index f154ec34..ff439568 100644 --- a/taglib/ape/apeproperties.h +++ b/taglib/ape/apeproperties.h @@ -84,8 +84,8 @@ namespace TagLib { void read(); - long findDescriptor(); - long findID3v2(); + offset_t findDescriptor(); + offset_t findID3v2(); void analyzeCurrent(); void analyzeOld(); diff --git a/taglib/ape/apetag.cpp b/taglib/ape/apetag.cpp index 3dcae8c0..31dccc48 100644 --- a/taglib/ape/apetag.cpp +++ b/taglib/ape/apetag.cpp @@ -49,7 +49,7 @@ public: TagPrivate() : file(0), footerLocation(-1), tagLength(0) {} TagLib::File *file; - long footerLocation; + offset_t footerLocation; long tagLength; Footer footer; @@ -66,7 +66,7 @@ APE::Tag::Tag() : TagLib::Tag() d = new TagPrivate; } -APE::Tag::Tag(TagLib::File *file, long footerLocation) : TagLib::Tag() +APE::Tag::Tag(TagLib::File *file, offset_t footerLocation) : TagLib::Tag() { d = new TagPrivate; d->file = file; diff --git a/taglib/ape/apetag.h b/taglib/ape/apetag.h index c1f12e29..9b78d5dd 100644 --- a/taglib/ape/apetag.h +++ b/taglib/ape/apetag.h @@ -66,7 +66,7 @@ namespace TagLib { * Create an APE tag and parse the data in \a file with APE footer at * \a tagOffset. */ - Tag(TagLib::File *file, long footerLocation); + Tag(TagLib::File *file, offset_t footerLocation); /*! * Destroys this Tag instance. diff --git a/taglib/asf/asffile.cpp b/taglib/asf/asffile.cpp index 455631f8..d27fefcb 100644 --- a/taglib/asf/asffile.cpp +++ b/taglib/asf/asffile.cpp @@ -158,7 +158,7 @@ ASF::File::HeaderExtensionObject::~HeaderExtensionObject() void ASF::File::BaseObject::parse(ASF::File *file, unsigned int size) { data.clear(); - if (size > 24 && size <= (unsigned int)(file->length())) + if (size > 24 && static_cast(size) <= file->length()) data = file->readBlock(size - 24); else data = ByteVector::null; diff --git a/taglib/flac/flacfile.cpp b/taglib/flac/flacfile.cpp index c85d9590..d27bb555 100644 --- a/taglib/flac/flacfile.cpp +++ b/taglib/flac/flacfile.cpp @@ -78,10 +78,10 @@ public: } const ID3v2::FrameFactory *ID3v2FrameFactory; - long ID3v2Location; + offset_t ID3v2Location; uint ID3v2OriginalSize; - long ID3v1Location; + offset_t ID3v1Location; TagUnion tag; @@ -90,9 +90,9 @@ public: ByteVector xiphCommentData; List blocks; - long flacStart; - long streamStart; - long streamLength; + offset_t flacStart; + offset_t streamStart; + offset_t streamLength; bool scanned; bool hasXiphComment; @@ -237,7 +237,7 @@ bool FLAC::File::save() // Adjust the padding block(s) - long originalLength = d->streamStart - d->flacStart; + uint originalLength = static_cast(d->streamStart - d->flacStart); int paddingLength = originalLength - data.size() - 4; if (paddingLength < 0) { paddingLength = MinPaddingLength; @@ -356,7 +356,7 @@ ByteVector FLAC::File::xiphCommentData() const return (isValid() && d->hasXiphComment) ? d->xiphCommentData : ByteVector(); } -long FLAC::File::streamLength() +offset_t FLAC::File::streamLength() { return d->streamLength; } @@ -371,7 +371,7 @@ void FLAC::File::scan() if(!isValid()) return; - long nextBlockOffset; + offset_t nextBlockOffset; if(d->hasID3v2) nextBlockOffset = find("fLaC", d->ID3v2Location + d->ID3v2OriginalSize); @@ -486,13 +486,13 @@ void FLAC::File::scan() d->scanned = true; } -long FLAC::File::findID3v1() +offset_t FLAC::File::findID3v1() { if(!isValid()) return -1; seek(-128, End); - long p = tell(); + offset_t p = tell(); if(readBlock(3) == ID3v1::Tag::fileIdentifier()) return p; @@ -500,7 +500,7 @@ long FLAC::File::findID3v1() return -1; } -long FLAC::File::findID3v2() +offset_t FLAC::File::findID3v2() { if(!isValid()) return -1; diff --git a/taglib/flac/flacfile.h b/taglib/flac/flacfile.h index 716d4478..6bbd85c9 100644 --- a/taglib/flac/flacfile.h +++ b/taglib/flac/flacfile.h @@ -215,7 +215,7 @@ namespace TagLib { * * \deprecated This method will not be public in a future release. */ - long streamLength(); // BIC: remove + offset_t streamLength(); // BIC: remove /*! * Returns a list of pictures attached to the FLAC file. @@ -247,10 +247,10 @@ namespace TagLib { void read(bool readProperties, Properties::ReadStyle propertiesStyle); void scan(); - long findID3v2(); - long findID3v1(); + offset_t findID3v2(); + offset_t findID3v1(); ByteVector xiphCommentData() const; - long findPaddingBreak(long nextPageOffset, long targetOffset, bool *isLast); + offset_t findPaddingBreak(long nextPageOffset, long targetOffset, bool *isLast); class FilePrivate; FilePrivate *d; diff --git a/taglib/flac/flacproperties.cpp b/taglib/flac/flacproperties.cpp index 8bdc5d8d..57de55f4 100644 --- a/taglib/flac/flacproperties.cpp +++ b/taglib/flac/flacproperties.cpp @@ -34,7 +34,7 @@ using namespace TagLib; class FLAC::Properties::PropertiesPrivate { public: - PropertiesPrivate(ByteVector d, long st, ReadStyle s) : + PropertiesPrivate(ByteVector d, offset_t st, ReadStyle s) : data(d), streamLength(st), style(s), @@ -46,7 +46,7 @@ public: sampleFrames(0) {} ByteVector data; - long streamLength; + offset_t streamLength; ReadStyle style; int length; int bitrate; @@ -61,7 +61,7 @@ public: // public members //////////////////////////////////////////////////////////////////////////////// -FLAC::Properties::Properties(ByteVector data, long streamLength, ReadStyle style) : AudioProperties(style) +FLAC::Properties::Properties(ByteVector data, offset_t streamLength, ReadStyle style) : AudioProperties(style) { d = new PropertiesPrivate(data, streamLength, style); read(); @@ -155,7 +155,7 @@ void FLAC::Properties::read() d->sampleFrames = (hi << 32) | lo; if(d->sampleRate > 0) - d->length = int(d->sampleFrames / d->sampleRate); + d->length = static_cast(d->sampleFrames / d->sampleRate); // Uncompressed bitrate: @@ -163,7 +163,7 @@ void FLAC::Properties::read() // Real bitrate: - d->bitrate = d->length > 0 ? ((d->streamLength * 8UL) / d->length) / 1000 : 0; + d->bitrate = d->length > 0 ? static_cast(d->streamLength * 8L / d->length / 1000) : 0; d->signature = d->data.mid(pos, 32); } diff --git a/taglib/flac/flacproperties.h b/taglib/flac/flacproperties.h index c1458981..8b59b4d9 100644 --- a/taglib/flac/flacproperties.h +++ b/taglib/flac/flacproperties.h @@ -50,7 +50,7 @@ namespace TagLib { * ByteVector \a data. */ // BIC: switch to const reference - Properties(ByteVector data, long streamLength, ReadStyle style = Average); + Properties(ByteVector data, offset_t streamLength, ReadStyle style = Average); /*! * Create an instance of FLAC::Properties with the data read from the diff --git a/taglib/it/itfile.cpp b/taglib/it/itfile.cpp index 4e049518..30638c97 100644 --- a/taglib/it/itfile.cpp +++ b/taglib/it/itfile.cpp @@ -155,7 +155,7 @@ bool IT::File::save() if(!readU16L(special)) return false; - ulong fileSize = File::length(); + ulong fileSize = static_cast(File::length()); if(special & Properties::MessageAttached) { seek(54); if(!readU16L(messageLength) || !readU32L(messageOffset)) diff --git a/taglib/mp4/mp4atom.cpp b/taglib/mp4/mp4atom.cpp index 1681ec80..92e0c17f 100644 --- a/taglib/mp4/mp4atom.cpp +++ b/taglib/mp4/mp4atom.cpp @@ -152,7 +152,7 @@ MP4::Atom::path(MP4::AtomList &path, const char *name1, const char *name2, const MP4::Atoms::Atoms(File *file) { file->seek(0, File::End); - long end = file->tell(); + offset_t end = file->tell(); file->seek(0); while(file->tell() + 8 <= end) { MP4::Atom *atom = new MP4::Atom(file); diff --git a/taglib/mp4/mp4atom.h b/taglib/mp4/mp4atom.h index ea5091a8..9a01f87d 100644 --- a/taglib/mp4/mp4atom.h +++ b/taglib/mp4/mp4atom.h @@ -82,7 +82,7 @@ namespace TagLib { Atom *find(const char *name1, const char *name2 = 0, const char *name3 = 0, const char *name4 = 0); bool path(AtomList &path, const char *name1, const char *name2 = 0, const char *name3 = 0); AtomList findall(const char *name, bool recursive = false); - long offset; + offset_t offset; long length; TagLib::ByteVector name; AtomList children; diff --git a/taglib/mp4/mp4tag.cpp b/taglib/mp4/mp4tag.cpp index f929ef64..162e66e9 100644 --- a/taglib/mp4/mp4tag.cpp +++ b/taglib/mp4/mp4tag.cpp @@ -514,7 +514,7 @@ MP4::Tag::updateParents(AtomList &path, long delta, int ignore) } void -MP4::Tag::updateOffsets(long delta, long offset) +MP4::Tag::updateOffsets(long delta, offset_t offset) { MP4::Atom *moov = d->atoms->find("moov"); if(moov) { @@ -597,7 +597,7 @@ MP4::Tag::saveNew(ByteVector &data) data = renderAtom("udta", data); } - long offset = path[path.size() - 1]->offset + 8; + offset_t offset = path[path.size() - 1]->offset + 8; d->file->insert(data, offset, 0); updateParents(path, data.size()); @@ -608,7 +608,7 @@ void MP4::Tag::saveExisting(ByteVector &data, AtomList &path) { MP4::Atom *ilst = path[path.size() - 1]; - long offset = ilst->offset; + offset_t offset = ilst->offset; long length = ilst->length; MP4::Atom *meta = path[path.size() - 2]; diff --git a/taglib/mp4/mp4tag.h b/taglib/mp4/mp4tag.h index b5ea6ebb..bee7298b 100644 --- a/taglib/mp4/mp4tag.h +++ b/taglib/mp4/mp4tag.h @@ -96,7 +96,7 @@ namespace TagLib { TagLib::ByteVector renderCovr(const ByteVector &name, Item &item); void updateParents(AtomList &path, long delta, int ignore = 0); - void updateOffsets(long delta, long offset); + void updateOffsets(long delta, offset_t offset); void saveNew(TagLib::ByteVector &data); void saveExisting(TagLib::ByteVector &data, AtomList &path); diff --git a/taglib/mpc/mpcfile.cpp b/taglib/mpc/mpcfile.cpp index 519a0467..5f377155 100644 --- a/taglib/mpc/mpcfile.cpp +++ b/taglib/mpc/mpcfile.cpp @@ -64,13 +64,13 @@ public: delete properties; } - long APELocation; + offset_t APELocation; uint APESize; - long ID3v1Location; + offset_t ID3v1Location; ID3v2::Header *ID3v2Header; - long ID3v2Location; + offset_t ID3v2Location; uint ID3v2Size; TagUnion tag; @@ -314,7 +314,7 @@ void MPC::File::read(bool readProperties, Properties::ReadStyle /* propertiesSty } } -long MPC::File::findAPE() +offset_t MPC::File::findAPE() { if(!isValid()) return -1; @@ -324,7 +324,7 @@ long MPC::File::findAPE() else seek(-32, End); - long p = tell(); + offset_t p = tell(); if(readBlock(8) == APE::Tag::fileIdentifier()) return p; @@ -332,13 +332,13 @@ long MPC::File::findAPE() return -1; } -long MPC::File::findID3v1() +offset_t MPC::File::findID3v1() { if(!isValid()) return -1; seek(-128, End); - long p = tell(); + offset_t p = tell(); if(readBlock(3) == ID3v1::Tag::fileIdentifier()) return p; @@ -346,7 +346,7 @@ long MPC::File::findID3v1() return -1; } -long MPC::File::findID3v2() +offset_t MPC::File::findID3v2() { if(!isValid()) return -1; diff --git a/taglib/mpc/mpcfile.h b/taglib/mpc/mpcfile.h index 167b768e..f3f4ac7d 100644 --- a/taglib/mpc/mpcfile.h +++ b/taglib/mpc/mpcfile.h @@ -191,9 +191,9 @@ namespace TagLib { void read(bool readProperties, Properties::ReadStyle propertiesStyle); void scan(); - long findAPE(); - long findID3v1(); - long findID3v2(); + offset_t findAPE(); + offset_t findID3v1(); + offset_t findID3v2(); class FilePrivate; FilePrivate *d; diff --git a/taglib/mpc/mpcproperties.cpp b/taglib/mpc/mpcproperties.cpp index 23d41987..85af7cf7 100644 --- a/taglib/mpc/mpcproperties.cpp +++ b/taglib/mpc/mpcproperties.cpp @@ -36,7 +36,7 @@ using namespace TagLib; class MPC::Properties::PropertiesPrivate { public: - PropertiesPrivate(long length, ReadStyle s) : + PropertiesPrivate(offset_t length, ReadStyle s) : streamLength(length), style(s), version(0), @@ -51,7 +51,7 @@ public: albumGain(0), albumPeak(0) {} - long streamLength; + offset_t streamLength; ReadStyle style; int version; int length; @@ -71,13 +71,13 @@ public: // public members //////////////////////////////////////////////////////////////////////////////// -MPC::Properties::Properties(const ByteVector &data, long streamLength, ReadStyle style) : AudioProperties(style) +MPC::Properties::Properties(const ByteVector &data, offset_t streamLength, ReadStyle style) : AudioProperties(style) { d = new PropertiesPrivate(streamLength, style); readSV7(data); } -MPC::Properties::Properties(File *file, long streamLength, ReadStyle style) : AudioProperties(style) +MPC::Properties::Properties(File *file, offset_t streamLength, ReadStyle style) : AudioProperties(style) { d = new PropertiesPrivate(streamLength, style); ByteVector magic = file->readBlock(4); @@ -214,7 +214,7 @@ void MPC::Properties::readSV8(File *file) d->channels = flags[7] * 8 + flags[6] * 4 + flags[5] * 2 + flags[4] + 1; if((d->sampleFrames - begSilence) != 0) - d->bitrate = (int)(d->streamLength * 8.0 * d->sampleRate / (d->sampleFrames - begSilence)); + d->bitrate = static_cast(d->streamLength * 8.0 * d->sampleRate / (d->sampleFrames - begSilence)); d->bitrate = d->bitrate / 1000; d->length = (d->sampleFrames - begSilence) / d->sampleRate; @@ -311,6 +311,6 @@ void MPC::Properties::readSV7(const ByteVector &data) d->length = d->sampleRate > 0 ? (d->sampleFrames + (d->sampleRate / 2)) / d->sampleRate : 0; if(!d->bitrate) - d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0; + d->bitrate = d->length > 0 ? static_cast(d->streamLength * 8L / d->length / 1000) : 0; } diff --git a/taglib/mpc/mpcproperties.h b/taglib/mpc/mpcproperties.h index adf40d83..1a66c64e 100644 --- a/taglib/mpc/mpcproperties.h +++ b/taglib/mpc/mpcproperties.h @@ -53,13 +53,13 @@ namespace TagLib { * * This constructor is deprecated. It only works for MPC version up to 7. */ - Properties(const ByteVector &data, long streamLength, ReadStyle style = Average); + Properties(const ByteVector &data, offset_t streamLength, ReadStyle style = Average); /*! * Create an instance of MPC::Properties with the data read directly * from a MPC::File. */ - Properties(File *file, long streamLength, ReadStyle style = Average); + Properties(File *file, offset_t streamLength, ReadStyle style = Average); /*! * Destroys this MPC::Properties instance. diff --git a/taglib/mpeg/id3v1/id3v1tag.cpp b/taglib/mpeg/id3v1/id3v1tag.cpp index ec83077f..891e0d0c 100644 --- a/taglib/mpeg/id3v1/id3v1tag.cpp +++ b/taglib/mpeg/id3v1/id3v1tag.cpp @@ -38,7 +38,7 @@ public: TagPrivate() : file(0), tagOffset(-1), track(0), genre(255) {} File *file; - long tagOffset; + offset_t tagOffset; String title; String artist; @@ -80,7 +80,7 @@ ID3v1::Tag::Tag() : TagLib::Tag() d = new TagPrivate; } -ID3v1::Tag::Tag(File *file, long tagOffset) : TagLib::Tag() +ID3v1::Tag::Tag(File *file, offset_t tagOffset) : TagLib::Tag() { d = new TagPrivate; d->file = file; diff --git a/taglib/mpeg/id3v1/id3v1tag.h b/taglib/mpeg/id3v1/id3v1tag.h index 4c0eba2c..27530887 100644 --- a/taglib/mpeg/id3v1/id3v1tag.h +++ b/taglib/mpeg/id3v1/id3v1tag.h @@ -111,7 +111,7 @@ namespace TagLib { * Create an ID3v1 tag and parse the data in \a file starting at * \a tagOffset. */ - Tag(File *file, long tagOffset); + Tag(File *file, offset_t tagOffset); /*! * Destroys this Tag instance. diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index c26ffef2..d0ef0d67 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -59,7 +59,7 @@ public: } File *file; - long tagOffset; + offset_t tagOffset; const FrameFactory *factory; Header header; @@ -101,7 +101,7 @@ ID3v2::Tag::Tag() : TagLib::Tag() d->factory = FrameFactory::instance(); } -ID3v2::Tag::Tag(File *file, long tagOffset, const FrameFactory *factory) : +ID3v2::Tag::Tag(File *file, offset_t tagOffset, const FrameFactory *factory) : TagLib::Tag() { d = new TagPrivate; diff --git a/taglib/mpeg/id3v2/id3v2tag.h b/taglib/mpeg/id3v2/id3v2tag.h index 946a83f5..43232d43 100644 --- a/taglib/mpeg/id3v2/id3v2tag.h +++ b/taglib/mpeg/id3v2/id3v2tag.h @@ -159,7 +159,7 @@ namespace TagLib { * * \see FrameFactory */ - Tag(File *file, long tagOffset, + Tag(File *file, offset_t tagOffset, const FrameFactory *factory = FrameFactory::instance()); /*! diff --git a/taglib/mpeg/mpegfile.cpp b/taglib/mpeg/mpegfile.cpp index ec094cdc..038c1c8b 100644 --- a/taglib/mpeg/mpegfile.cpp +++ b/taglib/mpeg/mpegfile.cpp @@ -70,14 +70,14 @@ public: const ID3v2::FrameFactory *ID3v2FrameFactory; - long ID3v2Location; + offset_t ID3v2Location; uint ID3v2OriginalSize; - long APELocation; - long APEFooterLocation; + offset_t APELocation; + offset_t APEFooterLocation; uint APEOriginalSize; - long ID3v1Location; + offset_t ID3v1Location; TagUnion tag; @@ -368,7 +368,7 @@ void MPEG::File::setID3v2FrameFactory(const ID3v2::FrameFactory *factory) d->ID3v2FrameFactory = factory; } -long MPEG::File::nextFrameOffset(long position) +offset_t MPEG::File::nextFrameOffset(offset_t position) { bool foundLastSyncPattern = false; @@ -394,13 +394,13 @@ long MPEG::File::nextFrameOffset(long position) } } -long MPEG::File::previousFrameOffset(long position) +offset_t MPEG::File::previousFrameOffset(offset_t position) { bool foundFirstSyncPattern = false; ByteVector buffer; while (position > 0) { - long size = ulong(position) < bufferSize() ? position : bufferSize(); + uint size = position < static_cast(bufferSize()) ? static_cast(position) : bufferSize(); position -= size; seek(position); @@ -422,9 +422,9 @@ long MPEG::File::previousFrameOffset(long position) return -1; } -long MPEG::File::firstFrameOffset() +offset_t MPEG::File::firstFrameOffset() { - long position = 0; + offset_t position = 0; if(ID3v2Tag()) position = d->ID3v2Location + ID3v2Tag()->header()->completeTagSize(); @@ -432,7 +432,7 @@ long MPEG::File::firstFrameOffset() return nextFrameOffset(position); } -long MPEG::File::lastFrameOffset() +offset_t MPEG::File::lastFrameOffset() { return previousFrameOffset(ID3v1Tag() ? d->ID3v1Location - 1 : length()); } @@ -503,7 +503,7 @@ void MPEG::File::read(bool readProperties, Properties::ReadStyle propertiesStyle ID3v1Tag(true); } -long MPEG::File::findID3v2() +offset_t MPEG::File::findID3v2() { // This method is based on the contents of TagLib::File::find(), but because // of some subtlteies -- specifically the need to look for the bit pattern of @@ -513,7 +513,7 @@ long MPEG::File::findID3v2() // The position in the file that the current buffer starts at. - long bufferOffset = 0; + offset_t bufferOffset = 0; ByteVector buffer; // These variables are used to keep track of a partial match that happens at @@ -525,7 +525,7 @@ long MPEG::File::findID3v2() // Save the location of the current read pointer. We will restore the // position using seek() before all returns. - long originalPosition = tell(); + offset_t originalPosition = tell(); // Start the search at the beginning of the file. @@ -614,11 +614,11 @@ long MPEG::File::findID3v2() return -1; } -long MPEG::File::findID3v1() +offset_t MPEG::File::findID3v1() { if(isValid()) { seek(-128, End); - long p = tell(); + offset_t p = tell(); if(readBlock(3) == ID3v1::Tag::fileIdentifier()) return p; @@ -631,7 +631,7 @@ void MPEG::File::findAPE() if(isValid()) { seek(d->hasID3v1 ? -160 : -32, End); - long p = tell(); + offset_t p = tell(); if(readBlock(8) == APE::Tag::fileIdentifier()) { d->APEFooterLocation = p; diff --git a/taglib/mpeg/mpegfile.h b/taglib/mpeg/mpegfile.h index f7b98364..b0d4a6db 100644 --- a/taglib/mpeg/mpegfile.h +++ b/taglib/mpeg/mpegfile.h @@ -282,24 +282,24 @@ namespace TagLib { /*! * Returns the position in the file of the first MPEG frame. */ - long firstFrameOffset(); + offset_t firstFrameOffset(); /*! * Returns the position in the file of the next MPEG frame, * using the current position as start */ - long nextFrameOffset(long position); + offset_t nextFrameOffset(offset_t position); /*! * Returns the position in the file of the previous MPEG frame, * using the current position as start */ - long previousFrameOffset(long position); + offset_t previousFrameOffset(offset_t position); /*! * Returns the position in the file of the last MPEG frame. */ - long lastFrameOffset(); + offset_t lastFrameOffset(); /*! * Returns whether or not the file on disk contains ID3v1 tag. @@ -321,8 +321,8 @@ namespace TagLib { File &operator=(const File &); void read(bool readProperties, Properties::ReadStyle propertiesStyle); - long findID3v2(); - long findID3v1(); + offset_t findID3v2(); + offset_t findID3v1(); void findAPE(); /*! diff --git a/taglib/mpeg/mpegproperties.cpp b/taglib/mpeg/mpegproperties.cpp index 3af95664..7fdc918b 100644 --- a/taglib/mpeg/mpegproperties.cpp +++ b/taglib/mpeg/mpegproperties.cpp @@ -151,7 +151,7 @@ void MPEG::Properties::read() // Since we've likely just looked for the ID3v1 tag, start at the end of the // file where we're least likely to have to have to move the disk head. - long last = d->file->lastFrameOffset(); + offset_t last = d->file->lastFrameOffset(); if(last < 0) { debug("MPEG::Properties::read() -- Could not find a valid last MPEG frame in the stream."); @@ -161,7 +161,7 @@ void MPEG::Properties::read() d->file->seek(last); Header lastHeader(d->file->readBlock(4)); - long first = d->file->firstFrameOffset(); + offset_t first = d->file->firstFrameOffset(); if(first < 0) { debug("MPEG::Properties::read() -- Could not find a valid first MPEG frame in the stream."); @@ -170,7 +170,7 @@ void MPEG::Properties::read() if(!lastHeader.isValid()) { - long pos = last; + offset_t pos = last; while(pos > first) { @@ -234,7 +234,7 @@ void MPEG::Properties::read() // Xing header. if(firstHeader.frameLength() > 0 && firstHeader.bitrate() > 0) { - int frames = (last - first) / firstHeader.frameLength() + 1; + int frames = static_cast((last - first) / firstHeader.frameLength() + 1); d->length = int(float(firstHeader.frameLength() * frames) / float(firstHeader.bitrate() * 125) + 0.5); diff --git a/taglib/ogg/flac/oggflacfile.cpp b/taglib/ogg/flac/oggflacfile.cpp index 9d9c303d..bf0d337e 100644 --- a/taglib/ogg/flac/oggflacfile.cpp +++ b/taglib/ogg/flac/oggflacfile.cpp @@ -56,8 +56,8 @@ public: Properties *properties; ByteVector streamInfoData; ByteVector xiphCommentData; - long streamStart; - long streamLength; + offset_t streamStart; + offset_t streamLength; bool scanned; bool hasXiphComment; @@ -173,7 +173,7 @@ ByteVector Ogg::FLAC::File::xiphCommentData() return d->xiphCommentData; } -long Ogg::FLAC::File::streamLength() +offset_t Ogg::FLAC::File::streamLength() { scan(); return d->streamLength; @@ -190,7 +190,7 @@ void Ogg::FLAC::File::scan() return; int ipacket = 0; - long overhead = 0; + offset_t overhead = 0; ByteVector metadataHeader = packet(ipacket); if(metadataHeader.isNull()) diff --git a/taglib/ogg/flac/oggflacfile.h b/taglib/ogg/flac/oggflacfile.h index 8558cfdf..2e08a55c 100644 --- a/taglib/ogg/flac/oggflacfile.h +++ b/taglib/ogg/flac/oggflacfile.h @@ -108,7 +108,7 @@ namespace TagLib { * Returns the length of the audio-stream, used by FLAC::Properties for * calculating the bitrate. */ - long streamLength(); + offset_t streamLength(); private: File(const File &); diff --git a/taglib/ogg/oggfile.cpp b/taglib/ogg/oggfile.cpp index cc30f9ce..b8047070 100644 --- a/taglib/ogg/oggfile.cpp +++ b/taglib/ogg/oggfile.cpp @@ -157,7 +157,7 @@ const Ogg::PageHeader *Ogg::File::firstPageHeader() if(d->firstPageHeader) return d->firstPageHeader->isValid() ? d->firstPageHeader : 0; - long firstPageHeaderOffset = find("OggS"); + offset_t firstPageHeaderOffset = find("OggS"); if(firstPageHeaderOffset < 0) return 0; @@ -171,7 +171,7 @@ const Ogg::PageHeader *Ogg::File::lastPageHeader() if(d->lastPageHeader) return d->lastPageHeader->isValid() ? d->lastPageHeader : 0; - long lastPageHeaderOffset = rfind("OggS"); + offset_t lastPageHeaderOffset = rfind("OggS"); if(lastPageHeaderOffset < 0) return 0; @@ -224,7 +224,7 @@ Ogg::File::File(IOStream *stream) : TagLib::File(stream) bool Ogg::File::nextPage() { - long nextPageOffset; + offset_t nextPageOffset; int currentPacket; if(d->pages.isEmpty()) { diff --git a/taglib/ogg/oggpage.cpp b/taglib/ogg/oggpage.cpp index e5f767ec..86d788e5 100644 --- a/taglib/ogg/oggpage.cpp +++ b/taglib/ogg/oggpage.cpp @@ -35,7 +35,7 @@ using namespace TagLib; class Ogg::Page::PagePrivate { public: - PagePrivate(File *f = 0, long pageOffset = -1) : + PagePrivate(File *f = 0, offset_t pageOffset = -1) : file(f), fileOffset(pageOffset), packetOffset(0), @@ -50,8 +50,8 @@ public: } File *file; - long fileOffset; - long packetOffset; + offset_t fileOffset; + offset_t packetOffset; int dataSize; List packetSizes; PageHeader header; @@ -63,7 +63,7 @@ public: // public members //////////////////////////////////////////////////////////////////////////////// -Ogg::Page::Page(Ogg::File *file, long pageOffset) +Ogg::Page::Page(Ogg::File *file, offset_t pageOffset) { d = new PagePrivate(file, pageOffset); } @@ -73,7 +73,7 @@ Ogg::Page::~Page() delete d; } -long Ogg::Page::fileOffset() const +offset_t Ogg::Page::fileOffset() const { return d->fileOffset; } diff --git a/taglib/ogg/oggpage.h b/taglib/ogg/oggpage.h index e9f4840c..ff905913 100644 --- a/taglib/ogg/oggpage.h +++ b/taglib/ogg/oggpage.h @@ -55,14 +55,14 @@ namespace TagLib { /*! * Read an Ogg page from the \a file at the position \a pageOffset. */ - Page(File *file, long pageOffset); + Page(File *file, offset_t pageOffset); virtual ~Page(); /*! * Returns the page's position within the file (in bytes). */ - long fileOffset() const; + offset_t fileOffset() const; /*! * Returns a pointer to the header for this page. This pointer will become diff --git a/taglib/ogg/oggpageheader.cpp b/taglib/ogg/oggpageheader.cpp index f9608ab7..9ac88ef6 100644 --- a/taglib/ogg/oggpageheader.cpp +++ b/taglib/ogg/oggpageheader.cpp @@ -39,7 +39,7 @@ using namespace TagLib; class Ogg::PageHeader::PageHeaderPrivate { public: - PageHeaderPrivate(File *f, long pageOffset) : + PageHeaderPrivate(File *f, offset_t pageOffset) : file(f), fileOffset(pageOffset), isValid(false), @@ -55,7 +55,7 @@ public: {} File *file; - long fileOffset; + offset_t fileOffset; bool isValid; List packetSizes; bool firstPacketContinued; @@ -73,7 +73,7 @@ public: // public members //////////////////////////////////////////////////////////////////////////////// -Ogg::PageHeader::PageHeader(Ogg::File *file, long pageOffset) +Ogg::PageHeader::PageHeader(Ogg::File *file, offset_t pageOffset) { d = new PageHeaderPrivate(file, pageOffset); if(file && pageOffset >= 0) diff --git a/taglib/ogg/oggpageheader.h b/taglib/ogg/oggpageheader.h index 742710a4..3cdec45b 100644 --- a/taglib/ogg/oggpageheader.h +++ b/taglib/ogg/oggpageheader.h @@ -52,7 +52,7 @@ namespace TagLib { * create a page with no (and as such, invalid) data that must be set * later. */ - PageHeader(File *file = 0, long pageOffset = -1); + PageHeader(File *file = 0, offset_t pageOffset = -1); /*! * Deletes this instance of the PageHeader. diff --git a/taglib/riff/rifffile.cpp b/taglib/riff/rifffile.cpp index a38e1c40..2a0e433c 100644 --- a/taglib/riff/rifffile.cpp +++ b/taglib/riff/rifffile.cpp @@ -35,7 +35,7 @@ using namespace TagLib; struct Chunk { ByteVector name; - TagLib::uint offset; + offset_t offset; TagLib::uint size; char padding; }; @@ -103,7 +103,7 @@ TagLib::uint RIFF::File::chunkDataSize(uint i) const return d->chunks[i].size; } -TagLib::uint RIFF::File::chunkOffset(uint i) const +offset_t RIFF::File::chunkOffset(uint i) const { return d->chunks[i].offset; } @@ -182,20 +182,25 @@ void RIFF::File::setChunkData(const ByteVector &name, const ByteVector &data, bo // Couldn't find an existing chunk, so let's create a new one. uint i = d->chunks.size() - 1; - ulong offset = d->chunks[i].offset + d->chunks[i].size; + offset_t offset = d->chunks[i].offset + d->chunks[i].size; // First we update the global size - d->size += (offset & 1) + data.size() + 8; + d->size += static_cast(offset & 1) + data.size() + 8; insert(ByteVector::fromUInt(d->size, d->endianness == BigEndian), 4, 4); // Now add the chunk to the file - writeChunk(name, data, offset, std::max(0, length() - offset), (offset & 1) ? 1 : 0); + writeChunk( + name, + data, + offset, + static_cast(std::max(0, length() - offset)), + static_cast(offset & 1)); // And update our internal structure - if (offset & 1) { + if(offset & 1) { d->chunks[i].padding = 1; offset++; } @@ -204,7 +209,7 @@ void RIFF::File::setChunkData(const ByteVector &name, const ByteVector &data, bo chunk.name = name; chunk.size = data.size(); chunk.offset = offset + 8; - chunk.padding = (data.size() & 0x01) ? 1 : 0; + chunk.padding = static_cast(data.size() & 1); d->chunks.push_back(chunk); } @@ -282,8 +287,8 @@ void RIFF::File::read() // check padding chunk.padding = 0; - long uPosNotPadded = tell(); - if((uPosNotPadded & 0x01) != 0) { + offset_t uPosNotPadded = tell(); + if(uPosNotPadded & 1) { ByteVector iByte = readBlock(1); if((iByte.size() != 1) || (iByte[0] != 0)) { // not well formed, re-seek @@ -299,7 +304,7 @@ void RIFF::File::read() } void RIFF::File::writeChunk(const ByteVector &name, const ByteVector &data, - ulong offset, ulong replace, uint leadingPadding) + offset_t offset, TagLib::uint replace, TagLib::uint leadingPadding) { ByteVector combined; if(leadingPadding) { diff --git a/taglib/riff/rifffile.h b/taglib/riff/rifffile.h index 274549ae..6e7dce3f 100644 --- a/taglib/riff/rifffile.h +++ b/taglib/riff/rifffile.h @@ -71,7 +71,7 @@ namespace TagLib { /*! * \return The offset within the file for the selected chunk number. */ - uint chunkOffset(uint i) const; + offset_t chunkOffset(uint i) const; /*! * \return The size of the chunk data. @@ -135,7 +135,7 @@ namespace TagLib { void read(); void writeChunk(const ByteVector &name, const ByteVector &data, - ulong offset, ulong replace = 0, + offset_t offset, uint replace = 0, uint leadingPadding = 0); class FilePrivate; diff --git a/taglib/toolkit/taglib.h b/taglib/toolkit/taglib.h index e941ca78..2c867da1 100755 --- a/taglib/toolkit/taglib.h +++ b/taglib/toolkit/taglib.h @@ -44,6 +44,17 @@ #include +#ifndef _WIN32 + +# ifndef _LARGEFILE_SOURCE +# define _LARGEFILE_SOURCE +# endif + +# define _FILE_OFFSET_BITS 64 +# include + +#endif + #ifdef __APPLE__ # include # define TAGLIB_ATOMIC_MAC @@ -83,6 +94,14 @@ namespace TagLib { typedef unsigned int uint; typedef unsigned long ulong; + // Offset or length type for I/O streams. + // In Win32, always 64bit. Otherwise, equivalent to off_t. +#ifdef _WIN32 + typedef LONGLONG offset_t; +#else + typedef off_t offset_t; +#endif + /*! * Unfortunately std::wstring isn't defined on some systems, (i.e. GCC < 3) * so I'm providing something here that should be constant. diff --git a/taglib/toolkit/tbytevectorstream.cpp b/taglib/toolkit/tbytevectorstream.cpp index dc480a26..9a3ace03 100644 --- a/taglib/toolkit/tbytevectorstream.cpp +++ b/taglib/toolkit/tbytevectorstream.cpp @@ -28,9 +28,9 @@ #include "tdebug.h" #include -#include - +#include #include +#include using namespace TagLib; @@ -40,7 +40,7 @@ public: ByteVectorStreamPrivate(const ByteVector &data); ByteVector data; - long position; + offset_t position; }; ByteVectorStream::ByteVectorStreamPrivate::ByteVectorStreamPrivate(const ByteVector &data) : @@ -68,12 +68,12 @@ FileName ByteVectorStream::name() const return FileName(""); // XXX do we need a name? } -ByteVector ByteVectorStream::readBlock(ulong length) +ByteVector ByteVectorStream::readBlock(uint length) { if(length == 0) return ByteVector::null; - ByteVector v = d->data.mid(d->position, length); + ByteVector v = d->data.mid(static_cast(d->position), length); d->position += v.size(); return v; } @@ -81,14 +81,14 @@ ByteVector ByteVectorStream::readBlock(ulong length) void ByteVectorStream::writeBlock(const ByteVector &data) { uint size = data.size(); - if(long(d->position + size) > length()) { + if(static_cast(d->position + size) > length()) truncate(d->position + size); - } + memcpy(d->data.data() + d->position, data.data(), size); d->position += size; } -void ByteVectorStream::insert(const ByteVector &data, ulong start, ulong replace) +void ByteVectorStream::insert(const ByteVector &data, offset_t start, uint replace) { long sizeDiff = data.size() - replace; if(sizeDiff < 0) { @@ -96,21 +96,27 @@ void ByteVectorStream::insert(const ByteVector &data, ulong start, ulong replace } else if(sizeDiff > 0) { truncate(length() + sizeDiff); - ulong readPosition = start + replace; - ulong writePosition = start + data.size(); - memmove(d->data.data() + writePosition, d->data.data() + readPosition, length() - sizeDiff - readPosition); + offset_t readPosition = start + replace; + offset_t writePosition = start + data.size(); + memmove( + d->data.data() + static_cast(writePosition), + d->data.data() + static_cast(readPosition), + static_cast(length() - sizeDiff - readPosition)); } seek(start); writeBlock(data); } -void ByteVectorStream::removeBlock(ulong start, ulong length) +void ByteVectorStream::removeBlock(offset_t start, uint length) { - ulong readPosition = start + length; - ulong writePosition = start; - if(readPosition < ulong(ByteVectorStream::length())) { - ulong bytesToMove = ByteVectorStream::length() - readPosition; - memmove(d->data.data() + writePosition, d->data.data() + readPosition, bytesToMove); + offset_t readPosition = start + length; + offset_t writePosition = start; + if(readPosition < ByteVectorStream::length()) { + size_t bytesToMove = static_cast(ByteVectorStream::length() - readPosition); + memmove( + d->data.data() + static_cast(writePosition), + d->data.data() + static_cast(readPosition), + bytesToMove); writePosition += bytesToMove; } d->position = writePosition; @@ -127,7 +133,7 @@ bool ByteVectorStream::isOpen() const return true; } -void ByteVectorStream::seek(long offset, Position p) +void ByteVectorStream::seek(offset_t offset, Position p) { switch(p) { case Beginning: @@ -146,19 +152,19 @@ void ByteVectorStream::clear() { } -long ByteVectorStream::tell() const +offset_t ByteVectorStream::tell() const { return d->position; } -long ByteVectorStream::length() +offset_t ByteVectorStream::length() { - return d->data.size(); + return static_cast(d->data.size()); } -void ByteVectorStream::truncate(long length) +void ByteVectorStream::truncate(offset_t length) { - d->data.resize(length); + d->data.resize(static_cast(length)); } ByteVector *ByteVectorStream::data() diff --git a/taglib/toolkit/tbytevectorstream.h b/taglib/toolkit/tbytevectorstream.h index 456b854e..7b455c82 100644 --- a/taglib/toolkit/tbytevectorstream.h +++ b/taglib/toolkit/tbytevectorstream.h @@ -61,7 +61,7 @@ namespace TagLib { /*! * Reads a block of size \a length at the current get pointer. */ - ByteVector readBlock(ulong length); + ByteVector readBlock(uint length); /*! * Attempts to write the block \a data at the current get pointer. If the @@ -81,7 +81,7 @@ namespace TagLib { * \note This method is slow since it requires rewriting all of the file * after the insertion point. */ - void insert(const ByteVector &data, ulong start = 0, ulong replace = 0); + void insert(const ByteVector &data, offset_t start = 0, uint replace = 0); /*! * Removes a block of the file starting a \a start and continuing for @@ -90,7 +90,7 @@ namespace TagLib { * \note This method is slow since it involves rewriting all of the file * after the removed portion. */ - void removeBlock(ulong start = 0, ulong length = 0); + void removeBlock(offset_t start = 0, uint length = 0); /*! * Returns true if the file is read only (or if the file can not be opened). @@ -109,7 +109,7 @@ namespace TagLib { * * \see Position */ - void seek(long offset, Position p = Beginning); + void seek(offset_t offset, Position p = Beginning); /*! * Reset the end-of-file and error flags on the file. @@ -119,17 +119,17 @@ namespace TagLib { /*! * Returns the current offset within the file. */ - long tell() const; + offset_t tell() const; /*! * Returns the length of the file. */ - long length(); + offset_t length(); /*! * Truncates the file to a \a length. */ - void truncate(long length); + void truncate(offset_t length); ByteVector *data(); diff --git a/taglib/toolkit/tfile.cpp b/taglib/toolkit/tfile.cpp index e6062199..7eac9f58 100644 --- a/taglib/toolkit/tfile.cpp +++ b/taglib/toolkit/tfile.cpp @@ -132,7 +132,7 @@ PropertyMap File::setProperties(const PropertyMap &properties) return tag()->setProperties(properties); } -ByteVector File::readBlock(ulong length) +ByteVector File::readBlock(uint length) { return d->stream->readBlock(length); } @@ -142,14 +142,14 @@ void File::writeBlock(const ByteVector &data) d->stream->writeBlock(data); } -long File::find(const ByteVector &pattern, long fromOffset, const ByteVector &before) +offset_t File::find(const ByteVector &pattern, offset_t fromOffset, const ByteVector &before) { if(!d->stream || pattern.size() > d->bufferSize) return -1; // The position in the file that the current buffer starts at. - long bufferOffset = fromOffset; + offset_t bufferOffset = fromOffset; ByteVector buffer; // These variables are used to keep track of a partial match that happens at @@ -161,7 +161,7 @@ long File::find(const ByteVector &pattern, long fromOffset, const ByteVector &be // Save the location of the current read pointer. We will restore the // position using seek() before all returns. - long originalPosition = tell(); + offset_t originalPosition = tell(); // Start the search at the offset. @@ -238,7 +238,7 @@ long File::find(const ByteVector &pattern, long fromOffset, const ByteVector &be } -long File::rfind(const ByteVector &pattern, long fromOffset, const ByteVector &before) +offset_t File::rfind(const ByteVector &pattern, offset_t fromOffset, const ByteVector &before) { if(!d->stream || pattern.size() > d->bufferSize) return -1; @@ -258,11 +258,11 @@ long File::rfind(const ByteVector &pattern, long fromOffset, const ByteVector &b // Save the location of the current read pointer. We will restore the // position using seek() before all returns. - long originalPosition = tell(); + offset_t originalPosition = tell(); // Start the search at the offset. - long bufferOffset; + offset_t bufferOffset; if(fromOffset == 0) { seek(-1 * int(d->bufferSize), End); bufferOffset = tell(); @@ -306,12 +306,12 @@ long File::rfind(const ByteVector &pattern, long fromOffset, const ByteVector &b return -1; } -void File::insert(const ByteVector &data, ulong start, ulong replace) +void File::insert(const ByteVector &data, offset_t start, uint replace) { d->stream->insert(data, start, replace); } -void File::removeBlock(ulong start, ulong length) +void File::removeBlock(offset_t start, uint length) { d->stream->removeBlock(start, length); } @@ -331,12 +331,12 @@ bool File::isValid() const return isOpen() && d->valid; } -void File::seek(long offset, Position p) +void File::seek(offset_t offset, Position p) { d->stream->seek(offset, IOStream::Position(p)); } -void File::truncate(long length) +void File::truncate(offset_t length) { d->stream->truncate(length); } @@ -346,12 +346,12 @@ void File::clear() d->stream->clear(); } -long File::tell() const +offset_t File::tell() const { return d->stream->tell(); } -long File::length() +offset_t File::length() { return d->stream->length(); } diff --git a/taglib/toolkit/tfile.h b/taglib/toolkit/tfile.h index 1dfab498..3194f62d 100644 --- a/taglib/toolkit/tfile.h +++ b/taglib/toolkit/tfile.h @@ -128,7 +128,7 @@ namespace TagLib { /*! * Reads a block of size \a length at the current get pointer. */ - ByteVector readBlock(ulong length); + ByteVector readBlock(uint length); /*! * Attempts to write the block \a data at the current get pointer. If the @@ -153,8 +153,8 @@ namespace TagLib { * \note This has the practial limitation that \a pattern can not be longer * than the buffer size used by readBlock(). Currently this is 1024 bytes. */ - long find(const ByteVector &pattern, - long fromOffset = 0, + offset_t find(const ByteVector &pattern, + offset_t fromOffset = 0, const ByteVector &before = ByteVector::null); /*! @@ -169,8 +169,8 @@ namespace TagLib { * \note This has the practial limitation that \a pattern can not be longer * than the buffer size used by readBlock(). Currently this is 1024 bytes. */ - long rfind(const ByteVector &pattern, - long fromOffset = 0, + offset_t rfind(const ByteVector &pattern, + offset_t fromOffset = 0, const ByteVector &before = ByteVector::null); /*! @@ -180,7 +180,7 @@ namespace TagLib { * \note This method is slow since it requires rewriting all of the file * after the insertion point. */ - void insert(const ByteVector &data, ulong start = 0, ulong replace = 0); + void insert(const ByteVector &data, offset_t start = 0, uint replace = 0); /*! * Removes a block of the file starting a \a start and continuing for @@ -189,7 +189,7 @@ namespace TagLib { * \note This method is slow since it involves rewriting all of the file * after the removed portion. */ - void removeBlock(ulong start = 0, ulong length = 0); + void removeBlock(offset_t start = 0, uint length = 0); /*! * Returns true if the file is read only (or if the file can not be opened). @@ -213,7 +213,7 @@ namespace TagLib { * * \see Position */ - void seek(long offset, Position p = Beginning); + void seek(offset_t offset, Position p = Beginning); /*! * Reset the end-of-file and error flags on the file. @@ -223,12 +223,12 @@ namespace TagLib { /*! * Returns the current offset within the file. */ - long tell() const; + offset_t tell() const; /*! * Returns the length of the file. */ - long length(); + offset_t length(); /*! * Returns true if \a file can be opened for reading. If the file does not @@ -276,7 +276,7 @@ namespace TagLib { /*! * Truncates the file to a \a length. */ - void truncate(long length); + void truncate(offset_t length); /*! * Returns the buffer size that is used for internal buffering. diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index 16efb579..69bd1291 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -27,19 +27,16 @@ #include "tstring.h" #include "tdebug.h" -#include #include #include -#ifdef _WIN32 -# include -# include -# include -#else +#ifndef _WIN32 +# include # include #endif #include +#include using namespace TagLib; @@ -114,7 +111,7 @@ public: FileNameHandle name; bool readOnly; - ulong size; + offset_t size; static const uint bufferSize = 1024; }; @@ -170,7 +167,7 @@ FileName FileStream::name() const return d->name; } -ByteVector FileStream::readBlock(ulong length) +ByteVector FileStream::readBlock(uint length) { if(!d->file) { debug("FileStream::readBlock() -- Invalid File"); @@ -181,14 +178,14 @@ ByteVector FileStream::readBlock(ulong length) return ByteVector::null; if(length > FileStreamPrivate::bufferSize && - length > ulong(FileStream::length())) + static_cast(length) > FileStream::length()) { - length = FileStream::length(); + length = static_cast(FileStream::length()); } - ByteVector v(static_cast(length)); - const int count = fread(v.data(), sizeof(char), length, d->file); - v.resize(count); + ByteVector v(length); + const size_t count = fread(v.data(), sizeof(char), length, d->file); + v.resize(static_cast(count)); return v; } @@ -205,7 +202,7 @@ void FileStream::writeBlock(const ByteVector &data) fwrite(data.data(), sizeof(char), data.size(), d->file); } -void FileStream::insert(const ByteVector &data, ulong start, ulong replace) +void FileStream::insert(const ByteVector &data, offset_t start, uint replace) { if(!d->file) return; @@ -232,15 +229,15 @@ void FileStream::insert(const ByteVector &data, ulong start, ulong replace) // the *differnce* in the tag sizes. We want to avoid overwriting parts // that aren't yet in memory, so this is necessary. - ulong bufferLength = bufferSize(); + size_t bufferLength = bufferSize(); while(data.size() - replace > bufferLength) bufferLength += bufferSize(); // Set where to start the reading and writing. - long readPosition = start + replace; - long writePosition = start; + offset_t readPosition = start + replace; + offset_t writePosition = start; ByteVector buffer; ByteVector aboutToOverwrite(static_cast(bufferLength)); @@ -252,7 +249,7 @@ void FileStream::insert(const ByteVector &data, ulong start, ulong replace) // That's a bit slower than using char *'s so, we're only doing it here. seek(readPosition); - int bytesRead = fread(aboutToOverwrite.data(), sizeof(char), bufferLength, d->file); + size_t bytesRead = fread(aboutToOverwrite.data(), sizeof(char), bufferLength, d->file); readPosition += bufferLength; seek(writePosition); @@ -281,7 +278,7 @@ void FileStream::insert(const ByteVector &data, ulong start, ulong replace) // Check to see if we just read the last block. We need to call clear() // if we did so that the last write succeeds. - if(ulong(bytesRead) < bufferLength) + if(bytesRead < bufferLength) clear(); // Seek to the write position and write our buffer. Increment the @@ -301,21 +298,24 @@ void FileStream::insert(const ByteVector &data, ulong start, ulong replace) bufferLength = bytesRead; } + + // Clear the file size cache. + d->size = 0; } -void FileStream::removeBlock(ulong start, ulong length) +void FileStream::removeBlock(offset_t start, uint length) { if(!d->file) return; - ulong bufferLength = bufferSize(); + size_t bufferLength = bufferSize(); - long readPosition = start + length; - long writePosition = start; + offset_t readPosition = start + length; + offset_t writePosition = start; ByteVector buffer(static_cast(bufferLength)); - ulong bytesRead = 1; + size_t bytesRead = 1; while(bytesRead != 0) { seek(readPosition); @@ -345,7 +345,7 @@ bool FileStream::isOpen() const return (d->file != NULL); } -void FileStream::seek(long offset, Position p) +void FileStream::seek(offset_t offset, Position p) { if(!d->file) { debug("File::seek() -- trying to seek in a file that isn't opened."); @@ -367,7 +367,9 @@ void FileStream::seek(long offset, Position p) break; } - SetFilePointer(d->file, offset, NULL, whence); + LARGE_INTEGER largeOffset = {}; + largeOffset.QuadPart = offset; + SetFilePointerEx(d->file, largeOffset, nullptr, whence); #else @@ -384,7 +386,15 @@ void FileStream::seek(long offset, Position p) break; } - fseek(d->file, offset, whence); +# ifdef _LARGEFILE_SOURCE + + fseeko(d->file, offset, whence); + +# else + + fseek(d->file, static_cast(offset), whence); + +# endif #endif } @@ -402,20 +412,33 @@ void FileStream::clear() #endif } -long FileStream::tell() const +offset_t FileStream::tell() const { #ifdef _WIN32 - return (long)SetFilePointer(d->file, 0, NULL, FILE_CURRENT); + LARGE_INTEGER largeOffset = {}; + LARGE_INTEGER newPointer; + + SetFilePointerEx(d->file, largeOffset, &newPointer, FILE_CURRENT); + + return newPointer.QuadPart; #else - return ftell(d->file); +# ifdef _LARGEFILE_SOURCE + + return ftello(d->file); + +# else + + return static_cast(ftell(d->file)); + +# endif #endif } -long FileStream::length() +offset_t FileStream::length() { // Do some caching in case we do multiple calls. @@ -425,31 +448,31 @@ long FileStream::length() if(!d->file) return 0; - long curpos = tell(); + offset_t currentPosition = tell(); seek(0, End); - long endpos = tell(); + offset_t endPosition = tell(); - seek(curpos, Beginning); + seek(currentPosition, Beginning); - d->size = endpos; - return endpos; + d->size = endPosition; + return endPosition; } //////////////////////////////////////////////////////////////////////////////// // protected members //////////////////////////////////////////////////////////////////////////////// -void FileStream::truncate(long length) +void FileStream::truncate(offset_t length) { #ifdef _WIN32 - long currentPos = tell(); + offset_t currentPosition = tell(); seek(length); SetEndOfFile(d->file); - seek(currentPos); + seek(currentPosition); #else diff --git a/taglib/toolkit/tfilestream.h b/taglib/toolkit/tfilestream.h index fa113b73..d3a6179e 100644 --- a/taglib/toolkit/tfilestream.h +++ b/taglib/toolkit/tfilestream.h @@ -67,7 +67,7 @@ namespace TagLib { /*! * Reads a block of size \a length at the current get pointer. */ - ByteVector readBlock(ulong length); + ByteVector readBlock(uint length); /*! * Attempts to write the block \a data at the current get pointer. If the @@ -87,7 +87,7 @@ namespace TagLib { * \note This method is slow since it requires rewriting all of the file * after the insertion point. */ - void insert(const ByteVector &data, ulong start = 0, ulong replace = 0); + void insert(const ByteVector &data, offset_t start = 0, uint replace = 0); /*! * Removes a block of the file starting a \a start and continuing for @@ -96,7 +96,7 @@ namespace TagLib { * \note This method is slow since it involves rewriting all of the file * after the removed portion. */ - void removeBlock(ulong start = 0, ulong length = 0); + void removeBlock(offset_t start = 0, uint length = 0); /*! * Returns true if the file is read only (or if the file can not be opened). @@ -115,7 +115,7 @@ namespace TagLib { * * \see Position */ - void seek(long offset, Position p = Beginning); + void seek(offset_t offset, Position p = Beginning); /*! * Reset the end-of-file and error flags on the file. @@ -125,17 +125,17 @@ namespace TagLib { /*! * Returns the current offset within the file. */ - long tell() const; + offset_t tell() const; /*! * Returns the length of the file. */ - long length(); + offset_t length(); /*! * Truncates the file to a \a length. */ - void truncate(long length); + void truncate(offset_t length); protected: diff --git a/taglib/toolkit/tiostream.h b/taglib/toolkit/tiostream.h index 3e7de22a..ac7ad7fc 100644 --- a/taglib/toolkit/tiostream.h +++ b/taglib/toolkit/tiostream.h @@ -80,7 +80,7 @@ namespace TagLib { /*! * Reads a block of size \a length at the current get pointer. */ - virtual ByteVector readBlock(ulong length) = 0; + virtual ByteVector readBlock(uint length) = 0; /*! * Attempts to write the block \a data at the current get pointer. If the @@ -100,7 +100,7 @@ namespace TagLib { * \note This method is slow since it requires rewriting all of the file * after the insertion point. */ - virtual void insert(const ByteVector &data, ulong start = 0, ulong replace = 0) = 0; + virtual void insert(const ByteVector &data, offset_t start = 0, uint replace = 0) = 0; /*! * Removes a block of the file starting a \a start and continuing for @@ -109,7 +109,7 @@ namespace TagLib { * \note This method is slow since it involves rewriting all of the file * after the removed portion. */ - virtual void removeBlock(ulong start = 0, ulong length = 0) = 0; + virtual void removeBlock(offset_t start = 0, uint length = 0) = 0; /*! * Returns true if the file is read only (or if the file can not be opened). @@ -128,7 +128,7 @@ namespace TagLib { * * \see Position */ - virtual void seek(long offset, Position p = Beginning) = 0; + virtual void seek(offset_t offset, Position p = Beginning) = 0; /*! * Reset the end-of-stream and error flags on the stream. @@ -138,17 +138,17 @@ namespace TagLib { /*! * Returns the current offset within the stream. */ - virtual long tell() const = 0; + virtual offset_t tell() const = 0; /*! * Returns the length of the stream. */ - virtual long length() = 0; + virtual offset_t length() = 0; /*! * Truncates the stream to a \a length. */ - virtual void truncate(long length) = 0; + virtual void truncate(offset_t length) = 0; private: IOStream(const IOStream &); diff --git a/taglib/trueaudio/trueaudiofile.cpp b/taglib/trueaudio/trueaudiofile.cpp index 9efc6e9d..06879447 100644 --- a/taglib/trueaudio/trueaudiofile.cpp +++ b/taglib/trueaudio/trueaudiofile.cpp @@ -64,10 +64,10 @@ public: } const ID3v2::FrameFactory *ID3v2FrameFactory; - long ID3v2Location; + offset_t ID3v2Location; uint ID3v2OriginalSize; - long ID3v1Location; + offset_t ID3v1Location; TagUnion tag; @@ -284,13 +284,13 @@ void TrueAudio::File::read(bool readProperties, Properties::ReadStyle /* propert } } -long TrueAudio::File::findID3v1() +offset_t TrueAudio::File::findID3v1() { if(!isValid()) return -1; seek(-128, End); - long p = tell(); + offset_t p = tell(); if(readBlock(3) == ID3v1::Tag::fileIdentifier()) return p; @@ -298,7 +298,7 @@ long TrueAudio::File::findID3v1() return -1; } -long TrueAudio::File::findID3v2() +offset_t TrueAudio::File::findID3v2() { if(!isValid()) return -1; diff --git a/taglib/trueaudio/trueaudiofile.h b/taglib/trueaudio/trueaudiofile.h index e3e1fe62..8b8b0c05 100644 --- a/taglib/trueaudio/trueaudiofile.h +++ b/taglib/trueaudio/trueaudiofile.h @@ -206,8 +206,8 @@ namespace TagLib { void read(bool readProperties, Properties::ReadStyle propertiesStyle); void scan(); - long findID3v1(); - long findID3v2(); + offset_t findID3v1(); + offset_t findID3v2(); class FilePrivate; FilePrivate *d; diff --git a/taglib/trueaudio/trueaudioproperties.cpp b/taglib/trueaudio/trueaudioproperties.cpp index 9b251ff1..43423d9c 100644 --- a/taglib/trueaudio/trueaudioproperties.cpp +++ b/taglib/trueaudio/trueaudioproperties.cpp @@ -39,7 +39,7 @@ using namespace TagLib; class TrueAudio::Properties::PropertiesPrivate { public: - PropertiesPrivate(const ByteVector &d, long length, ReadStyle s) : + PropertiesPrivate(const ByteVector &d, offset_t length, ReadStyle s) : data(d), streamLength(length), style(s), @@ -52,7 +52,7 @@ public: sampleFrames(0) {} ByteVector data; - long streamLength; + offset_t streamLength; ReadStyle style; int version; int length; @@ -67,7 +67,7 @@ public: // public members //////////////////////////////////////////////////////////////////////////////// -TrueAudio::Properties::Properties(const ByteVector &data, long streamLength, ReadStyle style) : AudioProperties(style) +TrueAudio::Properties::Properties(const ByteVector &data, offset_t streamLength, ReadStyle style) : AudioProperties(style) { d = new PropertiesPrivate(data, streamLength, style); read(); @@ -145,6 +145,6 @@ void TrueAudio::Properties::read() d->sampleFrames = d->data.mid(pos, 4).toUInt(false); d->length = d->sampleRate > 0 ? d->sampleFrames / d->sampleRate : 0; - d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0; + d->bitrate = d->length > 0 ? static_cast(d->streamLength * 8L / d->length / 1000) : 0; } } diff --git a/taglib/trueaudio/trueaudioproperties.h b/taglib/trueaudio/trueaudioproperties.h index 126b6788..67354696 100644 --- a/taglib/trueaudio/trueaudioproperties.h +++ b/taglib/trueaudio/trueaudioproperties.h @@ -54,7 +54,7 @@ namespace TagLib { * Create an instance of TrueAudio::Properties with the data read from the * ByteVector \a data. */ - Properties(const ByteVector &data, long streamLength, ReadStyle style = Average); + Properties(const ByteVector &data, offset_t streamLength, ReadStyle style = Average); /*! * Destroys this TrueAudio::Properties instance. diff --git a/taglib/wavpack/wavpackfile.cpp b/taglib/wavpack/wavpackfile.cpp index 49f7923e..8fe78830 100644 --- a/taglib/wavpack/wavpackfile.cpp +++ b/taglib/wavpack/wavpackfile.cpp @@ -62,10 +62,10 @@ public: delete properties; } - long APELocation; + offset_t APELocation; uint APESize; - long ID3v1Location; + offset_t ID3v1Location; TagUnion tag; @@ -261,7 +261,7 @@ void WavPack::File::read(bool readProperties, Properties::ReadStyle /* propertie } } -long WavPack::File::findAPE() +offset_t WavPack::File::findAPE() { if(!isValid()) return -1; @@ -271,7 +271,7 @@ long WavPack::File::findAPE() else seek(-32, End); - long p = tell(); + offset_t p = tell(); if(readBlock(8) == APE::Tag::fileIdentifier()) return p; @@ -279,13 +279,13 @@ long WavPack::File::findAPE() return -1; } -long WavPack::File::findID3v1() +offset_t WavPack::File::findID3v1() { if(!isValid()) return -1; seek(-128, End); - long p = tell(); + offset_t p = tell(); if(readBlock(3) == ID3v1::Tag::fileIdentifier()) return p; diff --git a/taglib/wavpack/wavpackfile.h b/taglib/wavpack/wavpackfile.h index 5bbbc65a..cb0dfab9 100644 --- a/taglib/wavpack/wavpackfile.h +++ b/taglib/wavpack/wavpackfile.h @@ -177,8 +177,8 @@ namespace TagLib { void read(bool readProperties, Properties::ReadStyle propertiesStyle); void scan(); - long findID3v1(); - long findAPE(); + offset_t findID3v1(); + offset_t findAPE(); class FilePrivate; FilePrivate *d; diff --git a/taglib/wavpack/wavpackproperties.cpp b/taglib/wavpack/wavpackproperties.cpp index 1715f425..73d914dc 100644 --- a/taglib/wavpack/wavpackproperties.cpp +++ b/taglib/wavpack/wavpackproperties.cpp @@ -38,7 +38,7 @@ using namespace TagLib; class WavPack::Properties::PropertiesPrivate { public: - PropertiesPrivate(const ByteVector &d, long length, ReadStyle s) : + PropertiesPrivate(const ByteVector &d, offset_t length, ReadStyle s) : data(d), streamLength(length), style(s), @@ -52,7 +52,7 @@ public: file(0) {} ByteVector data; - long streamLength; + offset_t streamLength; ReadStyle style; int length; int bitrate; @@ -68,13 +68,13 @@ public: // public members //////////////////////////////////////////////////////////////////////////////// -WavPack::Properties::Properties(const ByteVector &data, long streamLength, ReadStyle style) : AudioProperties(style) +WavPack::Properties::Properties(const ByteVector &data, offset_t streamLength, ReadStyle style) : AudioProperties(style) { d = new PropertiesPrivate(data, streamLength, style); read(); } -WavPack::Properties::Properties(File *file, long streamLength, ReadStyle style) : AudioProperties(style) +WavPack::Properties::Properties(File *file, offset_t streamLength, ReadStyle style) : AudioProperties(style) { ByteVector data = file->readBlock(32); d = new PropertiesPrivate(data, streamLength, style); @@ -170,14 +170,14 @@ void WavPack::Properties::read() d->length = d->sampleRate > 0 ? (samples + (d->sampleRate / 2)) / d->sampleRate : 0; d->sampleFrames = samples; - d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0; + d->bitrate = d->length > 0 ? static_cast(d->streamLength * 8L / d->length / 1000) : 0; } unsigned int WavPack::Properties::seekFinalIndex() { ByteVector blockID("wvpk", 4); - long offset = d->streamLength; + offset_t offset = d->streamLength; while(offset > 0) { offset = d->file->rfind(blockID, offset); if(offset == -1) diff --git a/taglib/wavpack/wavpackproperties.h b/taglib/wavpack/wavpackproperties.h index bd2209da..0766b422 100644 --- a/taglib/wavpack/wavpackproperties.h +++ b/taglib/wavpack/wavpackproperties.h @@ -58,13 +58,13 @@ namespace TagLib { * \deprecated This constructor will be dropped in favor of the one below * in a future version. */ - Properties(const ByteVector &data, long streamLength, ReadStyle style = Average); + Properties(const ByteVector &data, offset_t streamLength, ReadStyle style = Average); /*! * Create an instance of WavPack::Properties. */ // BIC: merge with the above constructor - Properties(File *file, long streamLength, ReadStyle style = Average); + Properties(File *file, offset_t streamLength, ReadStyle style = Average); /*! * Destroys this WavPack::Properties instance.