Differences From Artifact [9167fd4ad1]:
- File src/OFFile.m — part of check-in [1ffd8f9f16] at 2017-06-04 18:16:19 on branch trunk — OFFile: Make sure to not leak handles on MorphOS (user: js, size: 10840) [annotate] [blame] [check-ins using]
To Artifact [4cea821d7a]:
- File
src/OFFile.m
— part of check-in
[c9621825fc]
at
2017-06-04 18:48:03
on branch trunk
— Treat MorphOS + ixemul as a separate platform
This reduces the ifdef hell and makes much more sense, as with ixemul,
no native calls are allowed. (user: js, size: 10653) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
65 66 67 68 69 70 71 | #ifndef O_EXCL # define O_EXCL 0 #endif #ifndef O_EXLOCK # define O_EXLOCK 0 #endif | | | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | #ifndef O_EXCL # define O_EXCL 0 #endif #ifndef O_EXLOCK # define O_EXLOCK 0 #endif #ifndef OF_MORPHOS # define closeHandle(h) close(h) #else static OFDataArray *openHandles = nil; static void closeHandle(of_file_handle_t handle) { |
︙ | ︙ | |||
96 97 98 99 100 101 102 | size_t count = [openHandles count]; for (size_t i = 0; i < count; i++) Close(handles[i]); } #endif | | | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | size_t count = [openHandles count]; for (size_t i = 0; i < count; i++) Close(handles[i]); } #endif #ifndef OF_MORPHOS static int parseMode(const char *mode) { if (strcmp(mode, "r") == 0) return O_RDONLY; if (strcmp(mode, "w") == 0) return O_WRONLY | O_CREAT | O_TRUNC; |
︙ | ︙ | |||
188 189 190 191 192 193 194 | @implementation OFFile + (void)initialize { if (self != [OFFile class]) return; | | | 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | @implementation OFFile + (void)initialize { if (self != [OFFile class]) return; #ifdef OF_MORPHOS openHandles = [[OFDataArray alloc] initWithItemSize: sizeof(BPTR)]; #endif #ifdef OF_WII if (!fatInitDefault()) @throw [OFInitializationFailedException exceptionWithClass: self]; |
︙ | ︙ | |||
231 232 233 234 235 236 237 | { of_file_handle_t handle; @try { void *pool = objc_autoreleasePoolPush(); int flags; | | | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | { of_file_handle_t handle; @try { void *pool = objc_autoreleasePoolPush(); int flags; #ifndef OF_MORPHOS if ((flags = parseMode([mode UTF8String])) == -1) @throw [OFInvalidArgumentException exception]; flags |= O_CLOEXEC; # if defined(OF_WINDOWS) if ((handle = _wopen([path UTF16String], flags, |
︙ | ︙ | |||
327 328 329 330 331 332 333 | if (length > UINT_MAX) @throw [OFOutOfRangeException exception]; if ((ret = read(_handle, buffer, (unsigned int)length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: errno]; | | | 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | if (length > UINT_MAX) @throw [OFOutOfRangeException exception]; if ((ret = read(_handle, buffer, (unsigned int)length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: errno]; #elif defined(OF_MORPHOS) if (length > LONG_MAX) @throw [OFOutOfRangeException exception]; if ((ret = Read(_handle.handle, buffer, length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length]; #else |
︙ | ︙ | |||
362 363 364 365 366 367 368 | if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if (write(_handle, buffer, (int)length) != (int)length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length errNo: errno]; | | | 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if (write(_handle, buffer, (int)length) != (int)length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length errNo: errno]; #elif defined(OF_MORPHOS) if (length > LONG_MAX) @throw [OFOutOfRangeException exception]; if (_handle.append) { if (Seek64(_handle.handle, 0, OFFSET_END) == -1) @throw [OFWriteFailedException exceptionWithObject: self |
︙ | ︙ | |||
397 398 399 400 401 402 403 | of_offset_t ret; if (!OF_FILE_HANDLE_IS_VALID(_handle)) @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence]; | | | 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | of_offset_t ret; if (!OF_FILE_HANDLE_IS_VALID(_handle)) @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence]; #ifndef OF_MORPHOS # if defined(OF_WINDOWS) ret = _lseeki64(_handle, offset, whence); # elif defined(OF_HAVE_OFF64_T) ret = lseek64(_handle, offset, whence); # else ret = lseek(_handle, offset, whence); # endif |
︙ | ︙ |