Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -769,17 +769,21 @@ if (_fd == -1 || _atEndOfStream || write(_fd, buffer, length) < length) @throw [OFWriteFailedException exceptionWithStream: self requestedLength: length]; } -- (void)lowlevelSeekToOffset: (off_t)offset - whence: (int)whence +- (off_t)lowlevelSeekToOffset: (off_t)offset + whence: (int)whence { - if (lseek(_fd, offset, whence) == -1) + off_t ret = lseek(_fd, offset, whence); + + if (ret == -1) @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence]; + + return ret; } - (int)fileDescriptorForReading { return _fd; Index: src/OFSeekableStream.h ================================================================== --- src/OFSeekableStream.h +++ src/OFSeekableStream.h @@ -44,13 +44,14 @@ * Value | Description * ---------|--------------------------------------- * 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 */ -- (void)seekToOffset: (off_t)offset - whence: (int)whence; +- (off_t)seekToOffset: (off_t)offset + whence: (int)whence; /*! * @brief Seek the stream on the lowlevel. * * @warning Do not call this directly! @@ -64,9 +65,10 @@ * Value | Description * ---------|--------------------------------------- * 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 */ -- (void)lowlevelSeekToOffset: (off_t)offset - whence: (int)whence; +- (off_t)lowlevelSeekToOffset: (off_t)offset + whence: (int)whence; @end Index: src/OFSeekableStream.m ================================================================== --- src/OFSeekableStream.m +++ src/OFSeekableStream.m @@ -15,27 +15,33 @@ */ #include "config.h" #include +#include #import "OFSeekableStream.h" @implementation OFSeekableStream -- (void)lowlevelSeekToOffset: (off_t)offset - whence: (int)whence +- (off_t)lowlevelSeekToOffset: (off_t)offset + whence: (int)whence { [self doesNotRecognizeSelector: _cmd]; abort(); } -- (void)seekToOffset: (off_t)offset - whence: (int)whence +- (off_t)seekToOffset: (off_t)offset + whence: (int)whence { - [self lowlevelSeekToOffset: offset - whence: whence]; + if (whence == SEEK_CUR) + offset -= _readBufferLength; + + offset = [self lowlevelSeekToOffset: offset + whence: whence]; [self freeMemory: _readBuffer]; _readBuffer = NULL; _readBufferLength = 0; + + return offset; } @end