From 866b6c6129f82d951ba2f743b737e3057a1e6e1c Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 27 Apr 2022 19:16:37 -0400 Subject: [PATCH] Eliminate `off_t`. --- Machines/Apple/AppleII/AppleII.cpp | 2 +- Storage/Disk/DiskImage/Formats/AcornADF.cpp | 7 ++++--- Storage/Disk/DiskImage/Formats/FAT12.cpp | 2 +- Storage/Disk/DiskImage/Formats/MacintoshIMG.cpp | 10 +++++----- Storage/Disk/DiskImage/Formats/MacintoshIMG.hpp | 4 ++-- Storage/Disk/DiskImage/Formats/NIB.cpp | 8 ++++---- .../Disk/DiskImage/Formats/Utility/ImplicitSectors.cpp | 4 ++-- Storage/Disk/Track/PCMSegment.cpp | 8 ++++---- Storage/Disk/Track/PCMTrack.cpp | 8 ++++---- 9 files changed, 27 insertions(+), 26 deletions(-) diff --git a/Machines/Apple/AppleII/AppleII.cpp b/Machines/Apple/AppleII/AppleII.cpp index df993f263..14d68d279 100644 --- a/Machines/Apple/AppleII/AppleII.cpp +++ b/Machines/Apple/AppleII/AppleII.cpp @@ -478,7 +478,7 @@ template class ConcreteMachine: // The IIe and Enhanced IIe ROMs often distributed are oversized; trim if necessary. if(system == ROM::Name::AppleIIe || system == ROM::Name::AppleIIEnhancedE) { if(rom_.size() > 16128) { - rom_.erase(rom_.begin(), rom_.end() - off_t(16128)); + rom_.erase(rom_.begin(), rom_.end() - 16128); } } video_.set_character_rom(roms.find(character)->second); diff --git a/Storage/Disk/DiskImage/Formats/AcornADF.cpp b/Storage/Disk/DiskImage/Formats/AcornADF.cpp index e5b78e686..b7c4fd2d3 100644 --- a/Storage/Disk/DiskImage/Formats/AcornADF.cpp +++ b/Storage/Disk/DiskImage/Formats/AcornADF.cpp @@ -19,10 +19,11 @@ using namespace Storage::Disk; AcornADF::AcornADF(const std::string &file_name) : MFMSectorDump(file_name) { // Check that the disk image contains a whole number of sector. - if(file_.stats().st_size % off_t(128 << sector_size)) throw Error::InvalidFormat; + using sizeT = decltype(file_.stats().st_size); + if(file_.stats().st_size % sizeT(128 << sector_size)) throw Error::InvalidFormat; // Check that the disk image is at least large enough to hold an ADFS catalogue. - if(file_.stats().st_size < 7 * off_t(128 << sector_size)) throw Error::InvalidFormat; + if(file_.stats().st_size < 7 * sizeT(128 << sector_size)) throw Error::InvalidFormat; // Check that the initial directory's 'Hugo's are present. file_.seek(513, SEEK_SET); @@ -35,7 +36,7 @@ AcornADF::AcornADF(const std::string &file_name) : MFMSectorDump(file_name) { if(bytes[0] != 'H' || bytes[1] != 'u' || bytes[2] != 'g' || bytes[3] != 'o') throw Error::InvalidFormat; // Pick a number of heads; treat this image as double sided if it's too large to be single-sided. - head_count_ = 1 + (file_.stats().st_size > sectors_per_track * off_t(128 << sector_size) * 80); + head_count_ = 1 + (file_.stats().st_size > sectors_per_track * sizeT(128 << sector_size) * 80); // Announce disk geometry. set_geometry(sectors_per_track, sector_size, 0, true); diff --git a/Storage/Disk/DiskImage/Formats/FAT12.cpp b/Storage/Disk/DiskImage/Formats/FAT12.cpp index ebdb1b8bf..76c04bf10 100644 --- a/Storage/Disk/DiskImage/Formats/FAT12.cpp +++ b/Storage/Disk/DiskImage/Formats/FAT12.cpp @@ -16,7 +16,7 @@ FAT12::FAT12(const std::string &file_name) : MFMSectorDump(file_name) { // The only sanity check here is whether a sensible // geometry is encoded in the first sector, or can be guessed. - off_t file_size = file_.stats().st_size; + const auto file_size = file_.stats().st_size; if(file_size < 512) throw Error::InvalidFormat; diff --git a/Storage/Disk/DiskImage/Formats/MacintoshIMG.cpp b/Storage/Disk/DiskImage/Formats/MacintoshIMG.cpp index 074ac94f5..2bd311b80 100644 --- a/Storage/Disk/DiskImage/Formats/MacintoshIMG.cpp +++ b/Storage/Disk/DiskImage/Formats/MacintoshIMG.cpp @@ -23,7 +23,7 @@ using namespace Storage::Disk; -MacintoshIMG::MacintoshIMG(const std::string &file_name, FixedType type, size_t offset, off_t length) : +MacintoshIMG::MacintoshIMG(const std::string &file_name, FixedType type, size_t offset, size_t length) : file_(file_name) { switch(type) { @@ -51,7 +51,7 @@ MacintoshIMG::MacintoshIMG(const std::string &file_name) : if(!((name_length == 0x4c && magic_word == 0x4b) || (name_length == 0x00 && magic_word == 0x00))) throw Error::InvalidFormat; - construct_raw_gcr(0, -1); + construct_raw_gcr(0); } else { // DiskCopy 4.2 it is then: // @@ -122,10 +122,10 @@ MacintoshIMG::MacintoshIMG(const std::string &file_name) : } } -void MacintoshIMG::construct_raw_gcr(size_t offset, off_t size) { +void MacintoshIMG::construct_raw_gcr(size_t offset, size_t size) { is_diskCopy_file_ = false; - if(size == -1) { - size = file_.stats().st_size; + if(size == 0) { + size = size_t(file_.stats().st_size); } if(size != 819200 && size != 409600) throw Error::InvalidFormat; diff --git a/Storage/Disk/DiskImage/Formats/MacintoshIMG.hpp b/Storage/Disk/DiskImage/Formats/MacintoshIMG.hpp index c1abb1abb..dc95f89bc 100644 --- a/Storage/Disk/DiskImage/Formats/MacintoshIMG.hpp +++ b/Storage/Disk/DiskImage/Formats/MacintoshIMG.hpp @@ -42,7 +42,7 @@ class MacintoshIMG: public DiskImage { If @c offset and @c length are specified and non-zero, only that portion of the file will be modified. */ - MacintoshIMG(const std::string &file_name, FixedType type, size_t offset = 0, off_t length = -1); + MacintoshIMG(const std::string &file_name, FixedType type, size_t offset = 0, size_t length = 0); // implemented to satisfy @c Disk HeadPosition get_maximum_head_position() final; @@ -69,7 +69,7 @@ class MacintoshIMG: public DiskImage { std::mutex buffer_mutex_; uint32_t checksum(const std::vector &, size_t bytes_to_skip = 0); - void construct_raw_gcr(size_t offset, off_t length); + void construct_raw_gcr(size_t offset, size_t length = 0); long raw_offset_ = 0; }; diff --git a/Storage/Disk/DiskImage/Formats/NIB.cpp b/Storage/Disk/DiskImage/Formats/NIB.cpp index bf49d0d45..642d837ec 100644 --- a/Storage/Disk/DiskImage/Formats/NIB.cpp +++ b/Storage/Disk/DiskImage/Formats/NIB.cpp @@ -118,8 +118,8 @@ std::shared_ptr<::Storage::Disk::Track> NIB::get_track_at_position(::Storage::Di // when the initial sync was detected to carry over the index hole, // in which case there's nothing to copy. std::vector data_segment( - track_data.begin() + off_t(index), - track_data.begin() + off_t(location)); + track_data.begin() + ptrdiff_t(index), + track_data.begin() + ptrdiff_t(location)); segment += PCMSegment(data_segment); } @@ -138,7 +138,7 @@ std::shared_ptr<::Storage::Disk::Track> NIB::get_track_at_position(::Storage::Di // with sync, so no need to deal with that case here. if(index < track_length) { std::vector data_segment( - track_data.begin() + off_t(index), + track_data.begin() + ptrdiff_t(index), track_data.end()); segment += PCMSegment(data_segment); } @@ -181,7 +181,7 @@ void NIB::set_tracks(const std::map> &tra } else { while(track.size() < track_length) { std::vector extra_data(size_t(track_length) - track.size(), 0xff); - track.insert(track.begin() + off_t(sync_location), extra_data.begin(), extra_data.end()); + track.insert(track.begin() + ptrdiff_t(sync_location), extra_data.begin(), extra_data.end()); } } diff --git a/Storage/Disk/DiskImage/Formats/Utility/ImplicitSectors.cpp b/Storage/Disk/DiskImage/Formats/Utility/ImplicitSectors.cpp index 2bd8017a6..fa6993e74 100644 --- a/Storage/Disk/DiskImage/Formats/Utility/ImplicitSectors.cpp +++ b/Storage/Disk/DiskImage/Formats/Utility/ImplicitSectors.cpp @@ -21,8 +21,8 @@ using namespace Storage::Disk; std::shared_ptr Storage::Disk::track_for_sectors(const uint8_t *const source, int number_of_sectors, uint8_t track, uint8_t side, uint8_t first_sector, uint8_t size, bool is_double_density) { std::vector sectors; - off_t byte_size = off_t(128 << size); - off_t source_pointer = 0; + size_t byte_size = size_t(128 << size); + size_t source_pointer = 0; for(int sector = 0; sector < number_of_sectors; sector++) { sectors.emplace_back(); diff --git a/Storage/Disk/Track/PCMSegment.cpp b/Storage/Disk/Track/PCMSegment.cpp index 5dc4afe6b..d01859ea3 100644 --- a/Storage/Disk/Track/PCMSegment.cpp +++ b/Storage/Disk/Track/PCMSegment.cpp @@ -60,12 +60,12 @@ void PCMSegment::rotate_right(size_t length) { // the left, do the opposite. std::vector data_copy; if(length > 0) { - data_copy.insert(data_copy.end(), data.end() - off_t(length), data.end()); - data.erase(data.end() - off_t(length), data.end()); + data_copy.insert(data_copy.end(), data.end() - ptrdiff_t(length), data.end()); + data.erase(data.end() - ptrdiff_t(length), data.end()); data.insert(data.begin(), data_copy.begin(), data_copy.end()); } else { - data_copy.insert(data_copy.end(), data.begin(), data.begin() - off_t(length)); - data.erase(data.begin(), data.begin() - off_t(length)); + data_copy.insert(data_copy.end(), data.begin(), data.begin() - ptrdiff_t(length)); + data.erase(data.begin(), data.begin() - ptrdiff_t(length)); data.insert(data.end(), data_copy.begin(), data_copy.end()); } } diff --git a/Storage/Disk/Track/PCMTrack.cpp b/Storage/Disk/Track/PCMTrack.cpp index 19bb7599c..c9e5a79d2 100644 --- a/Storage/Disk/Track/PCMTrack.cpp +++ b/Storage/Disk/Track/PCMTrack.cpp @@ -164,7 +164,7 @@ void PCMTrack::add_segment(const Time &start_time, const PCMSegment &segment, bo const size_t selected_end_bit = std::min(end_bit, destination.data.size()); // Reset the destination. - std::fill(destination.data.begin() + off_t(start_bit), destination.data.begin() + off_t(selected_end_bit), false); + std::fill(destination.data.begin() + ptrdiff_t(start_bit), destination.data.begin() + ptrdiff_t(selected_end_bit), false); // Step through the source data from start to finish, stopping early if it goes out of bounds. for(size_t bit = 0; bit < segment.data.size(); ++bit) { @@ -183,12 +183,12 @@ void PCMTrack::add_segment(const Time &start_time, const PCMSegment &segment, bo if(target_width >= destination.data.size()) { std::fill(destination.data.begin(), destination.data.end(), false); } else { - std::fill(destination.data.begin(), destination.data.begin() + off_t(end_bit % destination.data.size()), false); - std::fill(destination.data.begin() + off_t(start_bit), destination.data.end(), false); + std::fill(destination.data.begin(), destination.data.begin() + ptrdiff_t(end_bit % destination.data.size()), false); + std::fill(destination.data.begin() + ptrdiff_t(start_bit), destination.data.end(), false); } // Run backwards from final bit back to first, stopping early if overlapping the beginning. - for(off_t bit = off_t(segment.data.size()-1); bit >= 0; --bit) { + for(auto bit = ptrdiff_t(segment.data.size()-1); bit >= 0; --bit) { // Store flux transitions only; non-transitions can be ignored. if(segment.data[size_t(bit)]) { // Map to the proper output destination; stop if now potentially overwriting where we began.