Index: generators/TableGenerator.m ================================================================== --- generators/TableGenerator.m +++ generators/TableGenerator.m @@ -263,11 +263,11 @@ - (void)writeTablesToFile: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path - mode: @"wb"]; + mode: @"w"]; [file writeString: COPYRIGHT @"#include \"config.h\"\n" @"\n" @"#import \"OFString.h\"\n\n" @@ -709,11 +709,11 @@ - (void)writeHeaderToFile: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path - mode: @"wb"]; + mode: @"w"]; [file writeString: COPYRIGHT @"#import \"OFString.h\"\n\n"]; [file writeString: [OFString stringWithFormat: Index: src/OFApplication.m ================================================================== --- src/OFApplication.m +++ src/OFApplication.m @@ -288,11 +288,11 @@ if ([fileManager directoryExistsAtPath: path]) continue; file = [OFFile fileWithPath: path - mode: @"rb"]; + mode: @"r"]; value = [file readLineWithEncoding: encoding]; if (value != nil) [_environment setObject: value forKey: name]; Index: src/OFData.m ================================================================== --- src/OFData.m +++ src/OFData.m @@ -214,11 +214,11 @@ @throw [OFOutOfMemoryException exceptionWithRequestedSize: size]; @try { OFFile *file = [[OFFile alloc] initWithPath: path - mode: @"rb"]; + mode: @"r"]; @try { [file readIntoBuffer: buffer exactLength: size]; } @finally { [file release]; @@ -592,11 +592,11 @@ #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path { OFFile *file = [[OFFile alloc] initWithPath: path - mode: @"wb"]; + mode: @"w"]; @try { [file writeBuffer: _items length: _count * _itemSize]; } @finally { Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -47,22 +47,18 @@ * @param path The path to the file to open as a string * @param mode The mode in which the file should be opened.@n * Possible modes are: * Mode | Description * ---------------|------------------------------------- - * `r` | read-only - * `rb` | read-only, binary - * `r+` | read-write - * `rb+` or `r+b` | read-write, binary - * `w` | write-only, create, truncate - * `wb` | write-only, create, truncate, binary - * `w` | read-write, create, truncate - * `wb+` or `w+b` | read-write, create, truncate, binary - * `a` | write-only, create, append - * `ab` | write-only, create, append, binary - * `a+` | read-write, create, append - * `ab+` or `a+b` | read-write, create, append, binary + * `r` | Read-only + * `r+` | Read-write + * `w` | Write-only, create or truncate + * `wx` | Write-only, create or fail, exclusive + * `w+` | Read-write, create or truncate + * `w+x` | Read-write, create or fail, exclusive + * `a` | Write-only, create or append + * `a+` | Read-write, create or append * @return A new autoreleased OFFile */ + (instancetype)fileWithPath: (OFString *)path mode: (OFString *)mode; Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -107,38 +107,24 @@ static int parseMode(const char *mode) { if (strcmp(mode, "r") == 0) return O_RDONLY; + if (strcmp(mode, "r+") == 0) + return O_RDWR; if (strcmp(mode, "w") == 0) return O_WRONLY | O_CREAT | O_TRUNC; if (strcmp(mode, "wx") == 0) return O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK; - if (strcmp(mode, "a") == 0) - return O_WRONLY | O_CREAT | O_APPEND; - if (strcmp(mode, "rb") == 0) - return O_RDONLY | O_BINARY; - if (strcmp(mode, "wb") == 0) - return O_WRONLY | O_CREAT | O_TRUNC | O_BINARY; - if (strcmp(mode, "wbx") == 0) - return O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK; - if (strcmp(mode, "ab") == 0) - return O_WRONLY | O_CREAT | O_APPEND | O_BINARY; - if (strcmp(mode, "r+") == 0) - return O_RDWR; if (strcmp(mode, "w+") == 0) return O_RDWR | O_CREAT | O_TRUNC; - if (strcmp(mode, "a+") == 0) - return O_RDWR | O_CREAT | O_APPEND; - if (strcmp(mode, "r+b") == 0 || strcmp(mode, "rb+") == 0) - return O_RDWR | O_BINARY; - if (strcmp(mode, "w+b") == 0 || strcmp(mode, "wb+") == 0) - return O_RDWR | O_CREAT | O_TRUNC | O_BINARY; - if (strcmp(mode, "w+bx") == 0 || strcmp(mode, "wb+x") == 0) + if (strcmp(mode, "w+x") == 0) return O_RDWR | O_CREAT | O_EXCL | O_EXLOCK; - if (strcmp(mode, "ab+") == 0 || strcmp(mode, "a+b") == 0) - return O_RDWR | O_CREAT | O_APPEND | O_BINARY; + if (strcmp(mode, "a") == 0) + return O_WRONLY | O_CREAT | O_APPEND; + if (strcmp(mode, "a+") == 0) + return O_RDWR | O_CREAT | O_APPEND; return -1; } #else static int @@ -236,11 +222,11 @@ #ifndef OF_MORPHOS if ((flags = parseMode([mode UTF8String])) == -1) @throw [OFInvalidArgumentException exception]; - flags |= O_CLOEXEC; + flags |= O_BINARY | O_CLOEXEC; # if defined(OF_WINDOWS) if ((handle = _wopen([path UTF16String], flags, _S_IREAD | _S_IWRITE)) == -1) # elif defined(OF_HAVE_OFF64_T) Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -927,13 +927,13 @@ @throw [OFOutOfMemoryException exceptionWithRequestedSize: pageSize]; @try { sourceFile = [OFFile fileWithPath: source - mode: @"rb"]; + mode: @"r"]; destinationFile = [OFFile fileWithPath: destination - mode: @"wb"]; + mode: @"w"]; while (![sourceFile isAtEndOfStream]) { size_t length; length = [sourceFile readIntoBuffer: buffer Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -964,20 +964,20 @@ fileSize = [[OFFileManager defaultManager] sizeOfFileAtPath: path]; } @catch (OFStatItemFailedException *e) { @throw [OFOpenItemFailedException exceptionWithPath: path - mode: @"rb" + mode: @"r" errNo: errno]; } if (sizeof(of_offset_t) > sizeof(size_t) && fileSize > (of_offset_t)SIZE_MAX) @throw [OFOutOfRangeException exception]; file = [[OFFile alloc] initWithPath: path - mode: @"rb"]; + mode: @"r"]; @try { tmp = [self allocMemoryWithSize: (size_t)fileSize]; [file readIntoBuffer: tmp @@ -2766,11 +2766,11 @@ { void *pool = objc_autoreleasePoolPush(); OFFile *file; file = [OFFile fileWithPath: path - mode: @"wb"]; + mode: @"w"]; [file writeString: self encoding: encoding]; objc_autoreleasePoolPop(pool); } Index: src/OFTarArchive.m ================================================================== --- src/OFTarArchive.m +++ src/OFTarArchive.m @@ -50,11 +50,11 @@ #ifdef OF_HAVE_FILES - initWithPath: (OFString *)path { OFFile *file = [[OFFile alloc] initWithPath: path - mode: @"rb"]; + mode: @"r"]; @try { self = [self initWithStream: file]; } @finally { [file release]; } Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -280,11 +280,11 @@ #ifdef OF_HAVE_FILES - (void)parseFile: (OFString *)path { OFFile *file = [[OFFile alloc] initWithPath: path - mode: @"rb"]; + mode: @"r"]; @try { [self parseStream: file]; } @finally { [file release]; } Index: src/OFZIPArchive.m ================================================================== --- src/OFZIPArchive.m +++ src/OFZIPArchive.m @@ -172,11 +172,11 @@ #ifdef OF_HAVE_FILES - initWithPath: (OFString *)path { OFFile *file = [[OFFile alloc] initWithPath: path - mode: @"rb"]; + mode: @"r"]; @try { self = [self initWithSeekableStream: file]; } @finally { [file release]; } @@ -329,11 +329,11 @@ OFZIPArchive_LocalFileHeader *localFileHeader; int64_t offset64; if (entry == nil) @throw [OFOpenItemFailedException exceptionWithPath: path - mode: @"rb" + mode: @"r" errNo: ENOENT]; [_lastReturnedStream close]; [_lastReturnedStream release]; _lastReturnedStream = nil; Index: tests/OFHMACTests.m ================================================================== --- tests/OFHMACTests.m +++ tests/OFHMACTests.m @@ -65,11 +65,11 @@ @implementation TestsAppDelegate (OFHMACTests) - (void)HMACTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFFile *f = [OFFile fileWithPath: @"testfile.bin" - mode: @"rb"]; + mode: @"r"]; OFHMAC *HMAC_MD5, *HMAC_SHA1, *HMAC_RMD160; OFHMAC *HMAC_SHA256, *HMAC_SHA384, *HMAC_SHA512; TEST(@"+[HMACWithHashClass:] with MD5", (HMAC_MD5 = [OFHMAC HMACWithHashClass: [OFMD5Hash class]])) Index: tests/OFMD5HashTests.m ================================================================== --- tests/OFMD5HashTests.m +++ tests/OFMD5HashTests.m @@ -36,11 +36,11 @@ - (void)MD5HashTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMD5Hash *md5, *copy; OFFile *f = [OFFile fileWithPath: @"testfile.bin" - mode: @"rb"]; + mode: @"r"]; TEST(@"+[cryptoHash]", (md5 = [OFMD5Hash cryptoHash])) while (![f isAtEndOfStream]) { char buf[64]; Index: tests/OFRIPEMD160HashTests.m ================================================================== --- tests/OFRIPEMD160HashTests.m +++ tests/OFRIPEMD160HashTests.m @@ -37,11 +37,11 @@ - (void)RIPEMD160HashTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFRIPEMD160Hash *rmd160, *copy; OFFile *f = [OFFile fileWithPath: @"testfile.bin" - mode: @"rb"]; + mode: @"r"]; TEST(@"+[cryptoHash]", (rmd160 = [OFRIPEMD160Hash cryptoHash])) while (![f isAtEndOfStream]) { char buf[64]; Index: tests/OFSHA1HashTests.m ================================================================== --- tests/OFSHA1HashTests.m +++ tests/OFSHA1HashTests.m @@ -37,11 +37,11 @@ - (void)SHA1HashTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFSHA1Hash *sha1, *copy; OFFile *f = [OFFile fileWithPath: @"testfile.bin" - mode: @"rb"]; + mode: @"r"]; TEST(@"+[cryptoHash]", (sha1 = [OFSHA1Hash cryptoHash])) while (![f isAtEndOfStream]) { char buf[64]; Index: tests/OFSHA224HashTests.m ================================================================== --- tests/OFSHA224HashTests.m +++ tests/OFSHA224HashTests.m @@ -37,11 +37,11 @@ - (void)SHA224HashTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFSHA224Hash *sha224, *copy; OFFile *f = [OFFile fileWithPath: @"testfile.bin" - mode: @"rb"]; + mode: @"r"]; TEST(@"+[cryptoHash]", (sha224 = [OFSHA224Hash cryptoHash])) while (![f isAtEndOfStream]) { char buf[64]; Index: tests/OFSHA256HashTests.m ================================================================== --- tests/OFSHA256HashTests.m +++ tests/OFSHA256HashTests.m @@ -37,11 +37,11 @@ - (void)SHA256HashTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFSHA256Hash *sha256, *copy; OFFile *f = [OFFile fileWithPath: @"testfile.bin" - mode: @"rb"]; + mode: @"r"]; TEST(@"+[cryptoHash]", (sha256 = [OFSHA256Hash cryptoHash])) while (![f isAtEndOfStream]) { char buf[64]; Index: tests/OFSHA384HashTests.m ================================================================== --- tests/OFSHA384HashTests.m +++ tests/OFSHA384HashTests.m @@ -38,11 +38,11 @@ - (void)SHA384HashTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFSHA384Hash *sha384, *copy; OFFile *f = [OFFile fileWithPath: @"testfile.bin" - mode: @"rb"]; + mode: @"r"]; TEST(@"+[cryptoHash]", (sha384 = [OFSHA384Hash cryptoHash])) while (![f isAtEndOfStream]) { char buf[128]; Index: tests/OFSHA512HashTests.m ================================================================== --- tests/OFSHA512HashTests.m +++ tests/OFSHA512HashTests.m @@ -39,11 +39,11 @@ - (void)SHA512HashTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFSHA512Hash *sha512, *copy; OFFile *f = [OFFile fileWithPath: @"testfile.bin" - mode: @"rb"]; + mode: @"r"]; TEST(@"+[cryptoHash]", (sha512 = [OFSHA512Hash cryptoHash])) while (![f isAtEndOfStream]) { char buf[128]; Index: utils/ofhash/OFHash.m ================================================================== --- utils/ofhash/OFHash.m +++ utils/ofhash/OFHash.m @@ -118,11 +118,11 @@ if ([path isEqual: @"-"]) file = of_stdin; else { @try { file = [OFFile fileWithPath: path - mode: @"rb"]; + mode: @"r"]; } @catch (OFOpenItemFailedException *e) { OFString *error = [OFString stringWithCString: strerror([e errNo]) encoding: [OFLocalization encoding]]; Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -883,11 +883,11 @@ goto next; } @try { OFString *mode = - ([response statusCode] == 206 ? @"ab" : @"wb"); + ([response statusCode] == 206 ? @"a" : @"w"); _output = [[OFFile alloc] initWithPath: fileName mode: mode]; } @catch (OFOpenItemFailedException *e) { [of_stderr writeLine: OF_LOCALIZED(@"failed_to_open_output", Index: utils/ofzip/GZIPArchive.m ================================================================== --- utils/ofzip/GZIPArchive.m +++ utils/ofzip/GZIPArchive.m @@ -102,11 +102,11 @@ if (![app shouldExtractFile: fileName outFileName: fileName]) return; output = [OFFile fileWithPath: fileName - mode: @"wb"]; + mode: @"w"]; setPermissions(fileName, app->_archivePath); while (![_stream isAtEndOfStream]) { ssize_t length = [app copyBlockFromStream: _stream toStream: output Index: utils/ofzip/OFZIP.m ================================================================== --- utils/ofzip/OFZIP.m +++ utils/ofzip/OFZIP.m @@ -313,11 +313,11 @@ if (path == nil) return nil; @try { file = [OFFile fileWithPath: path - mode: @"rb"]; + mode: @"r"]; } @catch (OFOpenItemFailedException *e) { OFString *error = [OFString stringWithCString: strerror([e errNo]) encoding: [OFLocalization encoding]]; [of_stderr writeString: @"\r"]; Index: utils/ofzip/TarArchive.m ================================================================== --- utils/ofzip/TarArchive.m +++ utils/ofzip/TarArchive.m @@ -313,11 +313,11 @@ if (![app shouldExtractFile: fileName outFileName: outFileName]) goto outer_loop_end; output = [OFFile fileWithPath: outFileName - mode: @"wb"]; + mode: @"w"]; setPermissions(outFileName, entry); while (![entry isAtEndOfStream]) { ssize_t length = [app copyBlockFromStream: entry toStream: output Index: utils/ofzip/ZIPArchive.m ================================================================== --- utils/ofzip/ZIPArchive.m +++ utils/ofzip/ZIPArchive.m @@ -266,11 +266,11 @@ outFileName: outFileName]) goto outer_loop_end; stream = [_archive streamForReadingFile: fileName]; output = [OFFile fileWithPath: outFileName - mode: @"wb"]; + mode: @"w"]; setPermissions(outFileName, entry); while (![stream isAtEndOfStream]) { ssize_t length = [app copyBlockFromStream: stream toStream: output