Overview
Comment: | Introduce and use of_offset_t instead of off_t
The reason for this is that some systems, for example Android, use |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
46b89b1c8e460af5f0bf96d53285de83 |
User & Date: | js on 2015-01-03 20:42:30 |
Other Links: | manifest | tags |
Context
2015-01-03
| ||
20:57 | Update copyright check-in: cfd374b906 user: js tags: trunk | |
20:42 | Introduce and use of_offset_t instead of off_t check-in: 46b89b1c8e user: js tags: trunk | |
2014-12-24
| ||
15:31 | Update buildsys check-in: 331bce9d09 user: js tags: trunk | |
Changes
Modified src/OFDataArray.m from [eb19be5b1d] to [51267778f5].
︙ | ︙ | |||
148 149 150 151 152 153 154 | #ifdef OF_HAVE_FILES - initWithContentsOfFile: (OFString*)path { @try { OFFile *file = [[OFFile alloc] initWithPath: path mode: @"rb"]; | | | 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | #ifdef OF_HAVE_FILES - initWithContentsOfFile: (OFString*)path { @try { OFFile *file = [[OFFile alloc] initWithPath: path mode: @"rb"]; of_offset_t size = [OFFile sizeOfFileAtPath: path]; if (size > SIZE_MAX) @throw [OFOutOfRangeException exception]; self = [self initWithItemSize: 1 capacity: (size_t)size]; |
︙ | ︙ |
Modified src/OFFile.h from [a349ed870a] to [6f5a3bfdbb].
︙ | ︙ | |||
147 148 149 150 151 152 153 | + (void)changeCurrentDirectoryPath: (OFString*)path; /*! * @brief Returns the size of the specified file. * * @return The size of the specified file */ | | | 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | + (void)changeCurrentDirectoryPath: (OFString*)path; /*! * @brief Returns the size of the specified file. * * @return The size of the specified file */ + (of_offset_t)sizeOfFileAtPath: (OFString*)path; /*! * @brief Returns the date of the last modification of the file. * * @return The date of the last modification of the file */ + (OFDate*)modificationDateOfFileAtPath: (OFString*)path; |
︙ | ︙ |
Modified src/OFFile.m from [752c197aa2] to [10eb8531ab].
︙ | ︙ | |||
476 477 478 479 480 481 482 | #else if (_wchdir([path UTF16String]) != 0) #endif @throw [OFChangeCurrentDirectoryPathFailedException exceptionWithPath: path]; } | | < | | 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 | #else if (_wchdir([path UTF16String]) != 0) #endif @throw [OFChangeCurrentDirectoryPathFailedException exceptionWithPath: path]; } + (of_offset_t)sizeOfFileAtPath: (OFString*)path { of_stat_t s; if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) == -1) /* FIXME: Maybe use another exception? */ @throw [OFOpenFileFailedException exceptionWithPath: path mode: @"r"]; return s.st_size; } + (OFDate*)modificationDateOfFileAtPath: (OFString*)path { of_stat_t s; if (path == nil) |
︙ | ︙ | |||
971 972 973 974 975 976 977 | if (_fd == -1 || _atEndOfStream || write(_fd, buffer, (unsigned int)length) < length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length]; #endif } | | | | | 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 | if (_fd == -1 || _atEndOfStream || write(_fd, buffer, (unsigned int)length) < length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length]; #endif } - (of_offset_t)lowlevelSeekToOffset: (of_offset_t)offset whence: (int)whence { of_offset_t ret = lseek(_fd, offset, whence); if (ret == -1) @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence]; _atEndOfStream = false; |
︙ | ︙ |
Modified src/OFSeekableStream.h from [22230c5b39] to [0d5fe8bc05].
︙ | ︙ | |||
21 22 23 24 25 26 27 28 29 30 31 32 33 34 | # define __STDC_CONSTANT_MACROS #endif #include <sys/types.h> #import "OFStream.h" /*! * @class OFSeekableStream OFSeekableStream.h ObjFW/OFSeekableStream.h * * @brief A stream that supports seeking. * * @note If you want to subclass this, override * @ref lowlevelSeekToOffset:whence:. OFSeekableStream uses this method | > > > > > > | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | # define __STDC_CONSTANT_MACROS #endif #include <sys/types.h> #import "OFStream.h" #ifdef __ANDROID__ typedef long long of_offset_t; #else typedef off_t of_offset_t; #endif /*! * @class OFSeekableStream OFSeekableStream.h ObjFW/OFSeekableStream.h * * @brief A stream that supports seeking. * * @note If you want to subclass this, override * @ref lowlevelSeekToOffset:whence:. OFSeekableStream uses this method |
︙ | ︙ | |||
46 47 48 49 50 51 52 | * 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 */ | | | | | | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | * 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 */ - (of_offset_t)seekToOffset: (of_offset_t)offset whence: (int)whence; /*! * @brief Seek the stream on the lowlevel. * * @warning Do not call this directly! * * Override this with this method with your actual seek implementation when * subclassing! * * @param offset The offset to seek to * @param whence From where to seek.@n * Possible values are: * 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 */ - (of_offset_t)lowlevelSeekToOffset: (of_offset_t)offset whence: (int)whence; @end |
Modified src/OFSeekableStream.m from [a7e1d973bb] to [8b8b0c6a0a].
︙ | ︙ | |||
35 36 37 38 39 40 41 | @throw e; } } return [super init]; } | | | | | | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | @throw e; } } return [super init]; } - (of_offset_t)lowlevelSeekToOffset: (of_offset_t)offset whence: (int)whence { OF_UNRECOGNIZED_SELECTOR } - (of_offset_t)seekToOffset: (of_offset_t)offset whence: (int)whence { if (whence == SEEK_CUR) offset -= _readBufferLength; offset = [self lowlevelSeekToOffset: offset whence: whence]; |
︙ | ︙ |
Modified src/OFZIPArchive.m from [e1f5b7ea93] to [21935bfcfb].
︙ | ︙ | |||
74 75 76 77 78 79 80 | bool _hasDataDescriptor; uint64_t _size; uint32_t _CRC32; bool _atEndOfStream; } - initWithArchiveFile: (OFString*)path | | | 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | bool _hasDataDescriptor; uint64_t _size; uint32_t _CRC32; bool _atEndOfStream; } - initWithArchiveFile: (OFString*)path offset: (of_offset_t)offset localFileHeader: (OFZIPArchive_LocalFileHeader*)localFileHeader; @end uint32_t of_zip_archive_read_field32(uint8_t **data, uint16_t *size) { uint32_t field = 0; |
︙ | ︙ | |||
176 177 178 179 180 181 182 | [super dealloc]; } - (void)OF_readZIPInfo { void *pool = objc_autoreleasePoolPush(); uint16_t commentLength; | | | 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | [super dealloc]; } - (void)OF_readZIPInfo { void *pool = objc_autoreleasePoolPush(); uint16_t commentLength; of_offset_t offset = -22; bool valid = false; do { @try { [_file seekToOffset: offset whence: SEEK_END]; } @catch (OFSeekFailedException *e) { |
︙ | ︙ | |||
234 235 236 237 238 239 240 | /* * FIXME: Handle number of the disk containing ZIP64 end of * central directory record. */ [_file readLittleEndianInt32]; offset64 = [_file readLittleEndianInt64]; | | | | 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | /* * FIXME: Handle number of the disk containing ZIP64 end of * central directory record. */ [_file readLittleEndianInt32]; offset64 = [_file readLittleEndianInt64]; if ((of_offset_t)offset64 != offset64) @throw [OFOutOfRangeException exception]; [_file seekToOffset: (of_offset_t)offset64 whence: SEEK_SET]; if ([_file readLittleEndianInt32] != 0x06064B50) @throw [OFInvalidFormatException exception]; size = [_file readLittleEndianInt64]; if (size < 44) |
︙ | ︙ | |||
259 260 261 262 263 264 265 | _diskNumber = [_file readLittleEndianInt32]; _centralDirectoryDisk = [_file readLittleEndianInt32]; _centralDirectoryEntriesInDisk = [_file readLittleEndianInt64]; _centralDirectoryEntries = [_file readLittleEndianInt64]; _centralDirectorySize = [_file readLittleEndianInt64]; _centralDirectoryOffset = [_file readLittleEndianInt64]; | > | | | | 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | _diskNumber = [_file readLittleEndianInt32]; _centralDirectoryDisk = [_file readLittleEndianInt32]; _centralDirectoryEntriesInDisk = [_file readLittleEndianInt64]; _centralDirectoryEntries = [_file readLittleEndianInt64]; _centralDirectorySize = [_file readLittleEndianInt64]; _centralDirectoryOffset = [_file readLittleEndianInt64]; if ((of_offset_t)_centralDirectoryOffset != _centralDirectoryOffset) @throw [OFOutOfRangeException exception]; } objc_autoreleasePoolPop(pool); } - (void)OF_readEntries { void *pool = objc_autoreleasePoolPush(); size_t i; if ((of_offset_t)_centralDirectoryOffset != _centralDirectoryOffset) @throw [OFOutOfRangeException exception]; [_file seekToOffset: (of_offset_t)_centralDirectoryOffset whence: SEEK_SET]; _entries = [[OFMutableArray alloc] init]; _pathToEntryMap = [[OFMutableDictionary alloc] init]; for (i = 0; i < _centralDirectoryEntries; i++) { OFZIPArchiveEntry *entry = [[[OFZIPArchiveEntry alloc] |
︙ | ︙ | |||
314 315 316 317 318 319 320 | - (OFStream*)streamForReadingFile: (OFString*)path { OFStream *ret; void *pool = objc_autoreleasePoolPush(); OFZIPArchiveEntry *entry = [_pathToEntryMap objectForKey: path]; OFZIPArchive_LocalFileHeader *localFileHeader; | | | | | | 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | - (OFStream*)streamForReadingFile: (OFString*)path { OFStream *ret; void *pool = objc_autoreleasePoolPush(); OFZIPArchiveEntry *entry = [_pathToEntryMap objectForKey: path]; OFZIPArchive_LocalFileHeader *localFileHeader; uint64_t offset64; if (entry == nil) { errno = ENOENT; @throw [OFOpenFileFailedException exceptionWithPath: path mode: @"rb"]; } offset64 = [entry OF_localFileHeaderOffset]; if ((of_offset_t)offset64 != offset64) @throw [OFOutOfRangeException exception]; [_file seekToOffset: (of_offset_t)offset64 whence: SEEK_SET]; localFileHeader = [[[OFZIPArchive_LocalFileHeader alloc] initWithFile: _file] autorelease]; if (![localFileHeader matchesEntry: entry]) @throw [OFInvalidFormatException exception]; |
︙ | ︙ | |||
442 443 444 445 446 447 448 | return true; } @end @implementation OFZIPArchive_FileStream - initWithArchiveFile: (OFString*)path | | | 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | return true; } @end @implementation OFZIPArchive_FileStream - initWithArchiveFile: (OFString*)path offset: (of_offset_t)offset localFileHeader: (OFZIPArchive_LocalFileHeader*)localFileHeader { self = [super init]; @try { _file = [[OFFile alloc] initWithPath: path mode: @"rb"]; |
︙ | ︙ |
Modified src/exceptions/OFSeekFailedException.h from [07822635da] to [59c0ad721f].
︙ | ︙ | |||
10 11 12 13 14 15 16 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ | < < < < < | | | | | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" #import "OFSeekableStream.h" /*! * @class OFSeekFailedException \ * OFSeekFailedException.h ObjFW/OFSeekFailedException.h * * @brief An exception indicating that seeking in a stream failed. */ @interface OFSeekFailedException: OFException { OFSeekableStream *_stream; of_offset_t _offset; int _whence, _errNo; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain) OFSeekableStream *stream; @property (readonly) of_offset_t offset; @property (readonly) int whence, errNo; #endif /*! * @brief Creates a new, autoreleased seek failed exception. * * @param stream The stream for which seeking failed * @param offset The offset to which seeking failed * @param whence To what the offset is relative * @return A new, autoreleased seek failed exception */ + (instancetype)exceptionWithStream: (OFSeekableStream*)stream offset: (of_offset_t)offset whence: (int)whence; /*! * @brief Initializes an already allocated seek failed exception. * * @param stream The stream for which seeking failed * @param offset The offset to which seeking failed * @param whence To what the offset is relative * @return An initialized seek failed exception */ - initWithStream: (OFSeekableStream*)stream offset: (of_offset_t)offset whence: (int)whence; /*! * @brief Returns the stream for which seeking failed. * * @return The stream for which seeking failed */ - (OFSeekableStream*)stream; /*! * @brief Returns the offset to which seeking failed. * * @return The offset to which seeking failed */ - (of_offset_t)offset; /*! * @brief Returns to what the offset is relative. * * @return To what the offset is relative */ - (int)whence; |
︙ | ︙ |
Modified src/exceptions/OFSeekFailedException.m from [9c20229078] to [931636a4ee].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #import "OFString.h" #import "OFSeekableStream.h" #import "common.h" @implementation OFSeekFailedException + (instancetype)exceptionWithStream: (OFSeekableStream*)stream | | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #import "OFString.h" #import "OFSeekableStream.h" #import "common.h" @implementation OFSeekFailedException + (instancetype)exceptionWithStream: (OFSeekableStream*)stream offset: (of_offset_t)offset whence: (int)whence { return [[[self alloc] initWithStream: stream offset: offset whence: whence] autorelease]; } - init { OF_INVALID_INIT_METHOD } - initWithStream: (OFSeekableStream*)stream offset: (of_offset_t)offset whence: (int)whence { self = [super init]; _stream = [stream retain]; _offset = offset; _whence = whence; |
︙ | ︙ | |||
66 67 68 69 70 71 72 | } - (OFSeekableStream*)stream { OF_GETTER(_stream, true) } | | | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | } - (OFSeekableStream*)stream { OF_GETTER(_stream, true) } - (of_offset_t)offset { return _offset; } - (int)whence { return _whence; |
︙ | ︙ |