Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -448,13 +448,14 @@ #endif return (size_t)bytesWritten; } -- (OFFileOffset)lowlevelSeekToOffset: (OFFileOffset)offset whence: (int)whence +- (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset + whence: (int)whence { - OFFileOffset ret; + OFStreamOffset ret; if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_AMIGAOS Index: src/OFFileURLHandler.m ================================================================== --- src/OFFileURLHandler.m +++ src/OFFileURLHandler.m @@ -85,11 +85,11 @@ # endif #endif #if defined(OF_WINDOWS) || defined(OF_AMIGAOS) typedef struct { - OFFileOffset st_size; + OFStreamOffset st_size; unsigned int st_mode; OFTimeInterval st_atime, st_mtime, st_ctime; # ifdef OF_WINDOWS # define HAVE_STRUCT_STAT_ST_BIRTHTIME OFTimeInterval st_birthtime; Index: src/OFLHAArchive.m ================================================================== --- src/OFLHAArchive.m +++ src/OFLHAArchive.m @@ -60,11 +60,11 @@ @interface OFLHAArchiveFileWriteStream: OFStream { OFMutableLHAArchiveEntry *_entry; OFStringEncoding _encoding; OFSeekableStream *_stream; - OFFileOffset _headerOffset; + OFStreamOffset _headerOffset; uint32_t _bytesWritten; uint16_t _CRC16; } - (instancetype)of_initWithStream: (OFSeekableStream *)stream @@ -396,12 +396,12 @@ stream = _stream; } if ([stream isKindOfClass: [OFSeekableStream class]] && - (sizeof(OFFileOffset) > 4 || toRead != (OFFileOffset)toRead)) - [(OFSeekableStream *)stream seekToOffset: (OFFileOffset)toRead + (sizeof(OFStreamOffset) > 4 || toRead != (OFStreamOffset)toRead)) + [(OFSeekableStream *)stream seekToOffset: (OFStreamOffset)toRead whence: SEEK_CUR]; else { while (toRead > 0) { char buffer[512]; unsigned long long min = toRead; @@ -514,11 +514,11 @@ .fileDescriptorForWriting; } - (void)close { - OFFileOffset offset; + OFStreamOffset offset; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; _entry.uncompressedSize = _bytesWritten; Index: src/OFMemoryStream.m ================================================================== --- src/OFMemoryStream.m +++ src/OFMemoryStream.m @@ -44,11 +44,11 @@ writable: (bool)writable { self = [super init]; @try { - if (size > SSIZE_MAX || (ssize_t)size != (OFFileOffset)size) + if (size > SSIZE_MAX || (ssize_t)size != (OFStreamOffset)size) @throw [OFOutOfRangeException exception]; _address = address; _size = size; _writable = writable; @@ -99,32 +99,33 @@ - (bool)lowlevelIsAtEndOfStream { return (_position == _size); } -- (OFFileOffset)lowlevelSeekToOffset: (OFFileOffset)offset whence: (int)whence +- (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset + whence: (int)whence { - OFFileOffset new; + OFStreamOffset new; switch (whence) { case SEEK_SET: new = offset; break; case SEEK_CUR: - new = (OFFileOffset)_position + offset; + new = (OFStreamOffset)_position + offset; break; case SEEK_END: - new = (OFFileOffset)_size + offset; + new = (OFStreamOffset)_size + offset; break; default: @throw [OFInvalidArgumentException exception]; } - if (new < 0 || new > (OFFileOffset)_size) + if (new < 0 || new > (OFStreamOffset)_size) @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence errNo: EINVAL]; return (_position = (size_t)new); } @end Index: src/OFSeekableStream.h ================================================================== --- src/OFSeekableStream.h +++ src/OFSeekableStream.h @@ -29,19 +29,19 @@ #import "OFStream.h" OF_ASSUME_NONNULL_BEGIN #if defined(OF_WINDOWS) -typedef __int64 OFFileOffset; +typedef __int64 OFStreamOffset; #elif defined(OF_ANDROID) -typedef long long OFFileOffset; +typedef long long OFStreamOffset; #elif defined(OF_MORPHOS) -typedef signed long long OFFileOffset; +typedef signed long long OFStreamOffset; #elif defined(OF_HAVE_OFF64_T) -typedef off64_t OFFileOffset; +typedef off64_t OFStreamOffset; #else -typedef off_t OFFileOffset; +typedef off_t OFStreamOffset; #endif /** * @class OFSeekableStream OFSeekableStream.h ObjFW/OFSeekableStream.h * @@ -57,11 +57,11 @@ { OF_RESERVE_IVARS(OFSeekableStream, 4) } /** - * @brief Seeks to the specified absolute offset. + * @brief Seeks to the specified offset. * * @param offset The offset in bytes * @param whence From where to seek.@n * Possible values are: * Value | Description @@ -69,11 +69,11 @@ * `SEEK_SET` | Seek to the specified byte * `SEEK_CUR` | Seek to the current location + offset * `SEEK_END` | Seek to the end of the stream + offset * @return The new offset form the start of the file */ -- (OFFileOffset)seekToOffset: (OFFileOffset)offset whence: (int)whence; +- (OFStreamOffset)seekToOffset: (OFStreamOffset)offset whence: (int)whence; /** * @brief Seek the stream on the lowlevel. * * @warning Do not call this directly! @@ -89,9 +89,10 @@ * `SEEK_SET` | Seek to the specified byte * `SEEK_CUR` | Seek to the current location + offset * `SEEK_END` | Seek to the end of the stream + offset * @return The new offset from the start of the file */ -- (OFFileOffset)lowlevelSeekToOffset: (OFFileOffset)offset whence: (int)whence; +- (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset + whence: (int)whence; @end OF_ASSUME_NONNULL_END Index: src/OFSeekableStream.m ================================================================== --- src/OFSeekableStream.m +++ src/OFSeekableStream.m @@ -36,16 +36,17 @@ } return [super init]; } -- (OFFileOffset)lowlevelSeekToOffset: (OFFileOffset)offset whence: (int)whence +- (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset + whence: (int)whence { OF_UNRECOGNIZED_SELECTOR } -- (OFFileOffset)seekToOffset: (OFFileOffset)offset whence: (int)whence +- (OFStreamOffset)seekToOffset: (OFStreamOffset)offset whence: (int)whence { if (whence == SEEK_CUR) offset -= _readBufferLength; offset = [self lowlevelSeekToOffset: offset whence: whence]; Index: src/OFTarArchive.m ================================================================== --- src/OFTarArchive.m +++ src/OFTarArchive.m @@ -357,15 +357,17 @@ { if (_stream == nil || _skipped) return; if ([_stream isKindOfClass: [OFSeekableStream class]] && - _toRead <= INT64_MAX && (OFFileOffset)_toRead == (int64_t)_toRead) { + _toRead <= INT64_MAX && + (OFStreamOffset)_toRead == (int64_t)_toRead) { uint64_t size; - [(OFSeekableStream *)_stream seekToOffset: (OFFileOffset)_toRead - whence: SEEK_CUR]; + [(OFSeekableStream *)_stream + seekToOffset: (OFStreamOffset)_toRead + whence: SEEK_CUR]; _toRead = 0; size = _entry.size; Index: src/OFZIPArchive.m ================================================================== --- src/OFZIPArchive.m +++ src/OFZIPArchive.m @@ -140,11 +140,11 @@ return field; } static void seekOrThrowInvalidFormat(OFSeekableStream *stream, - OFFileOffset offset, int whence) + OFStreamOffset offset, int whence) { @try { [stream seekToOffset: offset whence: whence]; } @catch (OFSeekFailedException *e) { if (e.errNo == EINVAL) @@ -199,11 +199,11 @@ } if (_mode == modeAppend) { _offset = _centralDirectoryOffset; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, - (OFFileOffset)_offset, SEEK_SET); + (OFStreamOffset)_offset, SEEK_SET); } } @catch (id e) { /* * If we are in write or append mode, we do not want -[close] * to write anything to it on error - after all, it might not @@ -257,11 +257,11 @@ - (void)of_readZIPInfo { void *pool = objc_autoreleasePoolPush(); uint16_t commentLength; - OFFileOffset offset = -22; + OFStreamOffset offset = -22; bool valid = false; do { seekOrThrowInvalidFormat((OFSeekableStream *)_stream, offset, SEEK_END); @@ -309,15 +309,15 @@ * central directory record. */ [_stream readLittleEndianInt32]; offset64 = [_stream readLittleEndianInt64]; - if (offset64 < 0 || (OFFileOffset)offset64 != offset64) + if (offset64 < 0 || (OFStreamOffset)offset64 != offset64) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, - (OFFileOffset)offset64, SEEK_SET); + (OFStreamOffset)offset64, SEEK_SET); if ([_stream readLittleEndianInt32] != 0x06064B50) @throw [OFInvalidFormatException exception]; size = [_stream readLittleEndianInt64]; @@ -336,11 +336,11 @@ _centralDirectoryEntries = [_stream readLittleEndianInt64]; _centralDirectorySize = [_stream readLittleEndianInt64]; _centralDirectoryOffset = [_stream readLittleEndianInt64]; if (_centralDirectoryOffset < 0 || - (OFFileOffset)_centralDirectoryOffset != + (OFStreamOffset)_centralDirectoryOffset != _centralDirectoryOffset) @throw [OFOutOfRangeException exception]; } objc_autoreleasePoolPop(pool); @@ -349,15 +349,15 @@ - (void)of_readEntries { void *pool = objc_autoreleasePoolPush(); if (_centralDirectoryOffset < 0 || - (OFFileOffset)_centralDirectoryOffset != _centralDirectoryOffset) + (OFStreamOffset)_centralDirectoryOffset != _centralDirectoryOffset) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, - (OFFileOffset)_centralDirectoryOffset, SEEK_SET); + (OFStreamOffset)_centralDirectoryOffset, SEEK_SET); for (size_t i = 0; i < _centralDirectoryEntries; i++) { OFZIPArchiveEntry *entry = [[[OFZIPArchiveEntry alloc] of_initWithStream: _stream] autorelease]; @@ -445,15 +445,15 @@ errNo: ENOENT]; [self of_closeLastReturnedStream]; offset64 = entry.of_localFileHeaderOffset; - if (offset64 < 0 || (OFFileOffset)offset64 != offset64) + if (offset64 < 0 || (OFStreamOffset)offset64 != offset64) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, - (OFFileOffset)offset64, SEEK_SET); + (OFStreamOffset)offset64, SEEK_SET); localFileHeader = [[[OFZIPArchiveLocalFileHeader alloc] initWithStream: _stream] autorelease]; if (![localFileHeader matchesEntry: entry]) @throw [OFInvalidFormatException exception]; Index: src/exceptions/OFSeekFailedException.h ================================================================== --- src/exceptions/OFSeekFailedException.h +++ src/exceptions/OFSeekFailedException.h @@ -25,11 +25,11 @@ * @brief An exception indicating that seeking in a stream failed. */ @interface OFSeekFailedException: OFException { OFSeekableStream *_stream; - OFFileOffset _offset; + OFStreamOffset _offset; int _whence, _errNo; } /** * @brief The stream for which seeking failed. @@ -37,11 +37,11 @@ @property (readonly, nonatomic) OFSeekableStream *stream; /** * @brief The offset to which seeking failed. */ -@property (readonly, nonatomic) OFFileOffset offset; +@property (readonly, nonatomic) OFStreamOffset offset; /** * @brief To what the offset is relative. */ @property (readonly, nonatomic) int whence; @@ -59,11 +59,11 @@ * @param whence To what the offset is relative * @param errNo The errno of the error that occurred * @return A new, autoreleased seek failed exception */ + (instancetype)exceptionWithStream: (OFSeekableStream *)stream - offset: (OFFileOffset)offset + offset: (OFStreamOffset)offset whence: (int)whence errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; @@ -75,13 +75,13 @@ * @param whence To what the offset is relative * @param errNo The errno of the error that occurred * @return An initialized seek failed exception */ - (instancetype)initWithStream: (OFSeekableStream *)stream - offset: (OFFileOffset)offset + offset: (OFStreamOffset)offset whence: (int)whence errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END Index: src/exceptions/OFSeekFailedException.m ================================================================== --- src/exceptions/OFSeekFailedException.m +++ src/exceptions/OFSeekFailedException.m @@ -27,11 +27,11 @@ { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithStream: (OFSeekableStream *)stream - offset: (OFFileOffset)offset + offset: (OFStreamOffset)offset whence: (int)whence errNo: (int)errNo { return [[[self alloc] initWithStream: stream offset: offset @@ -43,11 +43,11 @@ { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFSeekableStream *)stream - offset: (OFFileOffset)offset + offset: (OFStreamOffset)offset whence: (int)whence errNo: (int)errNo { self = [super init];