Differences From Artifact [c3e373372b]:
- File
src/OFFile.m
— part of check-in
[f9cd4f9cab]
at
2017-06-05 15:51:48
on branch trunk
— OFStream: Don't throw when at end of stream
Instead, let reads return 0 and let writes append after the end. (user: js, size: 10565) [annotate] [blame] [check-ins using]
To Artifact [89ce8091b7]:
- File
src/OFFile.m
— part of check-in
[4f36894ce7]
at
2017-06-05 17:36:28
on branch trunk
— Clean up exceptions a little
This removes several initializers that omitted the errNo. Removing those
forces to think about whether there is a meaningful errNo to set instead
of just omitting it. (user: js, size: 11089) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
260 261 262 263 264 265 266 | handle.index = SIZE_MAX; if ((flags = parseMode([mode UTF8String], &handle.append)) == -1) @throw [OFInvalidArgumentException exception]; if ((handle.handle = Open([path cStringWithEncoding: | | > > > > > > > > > > > > > > > > > > > > > > | > > | > | 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 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | handle.index = SIZE_MAX; if ((flags = parseMode([mode UTF8String], &handle.append)) == -1) @throw [OFInvalidArgumentException exception]; if ((handle.handle = Open([path cStringWithEncoding: [OFLocalization encoding]], flags)) == 0) { int errNo; switch (IoErr()) { case ERROR_OBJECT_IN_USE: case ERROR_DISK_NOT_VALIDATED: errNo = EBUSY; break; case ERROR_OBJECT_NOT_FOUND: errNo = ENOENT; break; case ERROR_DISK_WRITE_PROTECTED: errNo = EROFS; break; case ERROR_WRITE_PROTECTED: case ERROR_READ_PROTECTED: errNo = EACCES; break; default: errNo = 0; break; } @throw [OFOpenItemFailedException exceptionWithPath: path mode: mode errNo: errNo]; } [openHandles addItem: &handle.handle]; handle.index = [openHandles count] - 1; if (handle.append) { if (Seek64(handle.handle, 0, OFFSET_END) == -1) { closeHandle(handle); @throw [OFOpenItemFailedException exceptionWithPath: path mode: mode errNo: EIO]; } } #endif objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; |
︙ | ︙ | |||
333 334 335 336 337 338 339 | 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 | | > | 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | 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 errNo: EIO]; #else if ((ret = read(_handle, buffer, length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: errno]; #endif |
︙ | ︙ | |||
369 370 371 372 373 374 375 | if (length > LONG_MAX) @throw [OFOutOfRangeException exception]; if (_handle.append) { if (Seek64(_handle.handle, 0, OFFSET_END) == -1) @throw [OFWriteFailedException exceptionWithObject: self | | > | > | 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | if (length > LONG_MAX) @throw [OFOutOfRangeException exception]; if (_handle.append) { if (Seek64(_handle.handle, 0, OFFSET_END) == -1) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length errNo: EIO]; } if (Write(_handle.handle, (void *)buffer, length) != (LONG)length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length errNo: EIO]; #else if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if (write(_handle, buffer, length) != (ssize_t)length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length |
︙ | ︙ | |||
427 428 429 430 431 432 433 | ret = -1; break; } if (ret == -1) @throw [OFSeekFailedException exceptionWithStream: self offset: offset | | > | 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | ret = -1; break; } if (ret == -1) @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence errNo: EINVAL]; #endif _atEndOfStream = false; return ret; } |
︙ | ︙ |