Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -262,24 +262,49 @@ if ((flags = parseMode([mode UTF8String], &handle.append)) == -1) @throw [OFInvalidArgumentException exception]; if ((handle.handle = Open([path cStringWithEncoding: - [OFLocalization encoding]], flags)) == 0) + [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]; + 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]; + mode: mode + errNo: EIO]; } } #endif objc_autoreleasePoolPop(pool); @@ -335,11 +360,12 @@ if (length > LONG_MAX) @throw [OFOutOfRangeException exception]; if ((ret = Read(_handle.handle, buffer, length)) < 0) @throw [OFReadFailedException exceptionWithObject: self - requestedLength: length]; + requestedLength: length + errNo: EIO]; #else if ((ret = read(_handle, buffer, length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: errno]; @@ -371,16 +397,18 @@ if (_handle.append) { if (Seek64(_handle.handle, 0, OFFSET_END) == -1) @throw [OFWriteFailedException exceptionWithObject: self - requestedLength: length]; + requestedLength: length + errNo: EIO]; } if (Write(_handle.handle, (void *)buffer, length) != (LONG)length) @throw [OFWriteFailedException exceptionWithObject: self - requestedLength: length]; + requestedLength: length + errNo: EIO]; #else if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if (write(_handle, buffer, length) != (ssize_t)length) @@ -429,11 +457,12 @@ } if (ret == -1) @throw [OFSeekFailedException exceptionWithStream: self offset: offset - whence: whence]; + whence: whence + errNo: EINVAL]; #endif _atEndOfStream = false; return ret; Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -323,10 +323,11 @@ encoding = [OFLocalization encoding]; if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL) @throw [OFOpenItemFailedException exceptionWithPath: path + mode: nil errNo: errno]; # if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS) [readdirMutex lock]; # endif @@ -391,10 +392,11 @@ if (GetLastError() == ERROR_FILE_NOT_FOUND) errNo = ENOENT; @throw [OFOpenItemFailedException exceptionWithPath: path + mode: nil errNo: errNo]; } @try { do { @@ -411,11 +413,12 @@ objc_autoreleasePoolPop(pool2); } while (FindNextFileW(handle, &fd)); if (GetLastError() != ERROR_NO_MORE_FILES) @throw [OFReadFailedException exceptionWithObject: self - requestedLength: 0]; + requestedLength: 0 + errNo: EIO]; } @finally { FindClose(handle); } objc_autoreleasePoolPop(pool); @@ -940,11 +943,12 @@ if (!CreateHardLinkW([destination UTF16String], [source UTF16String], NULL)) @throw [OFLinkFailedException exceptionWithSourcePath: source - destinationPath: destination]; + destinationPath: destination + errNo: 0]; objc_autoreleasePoolPop(pool); } #endif @@ -987,11 +991,12 @@ if (!func_CreateSymbolicLinkW([destination UTF16String], [source UTF16String], 0)) @throw [OFCreateSymbolicLinkFailedException exceptionWithSourcePath: source - destinationPath: destination]; + destinationPath: destination + errNo: 0]; objc_autoreleasePoolPop(pool); } #endif @@ -1031,11 +1036,12 @@ @throw [OFInvalidArgumentException exception]; if ((handle = CreateFileW([path UTF16String], 0, (FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT, NULL)) == INVALID_HANDLE_VALUE) - @throw [OFStatItemFailedException exceptionWithPath: path]; + @throw [OFStatItemFailedException exceptionWithPath: path + errNo: 0]; @try { union { char bytes[MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; REPARSE_DATA_BUFFER data; @@ -1045,15 +1051,17 @@ if (!DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, NULL, 0, buffer.bytes, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &size, NULL)) @throw [OFStatItemFailedException - exceptionWithPath: path]; + exceptionWithPath: path + errNo: 0]; if (buffer.data.ReparseTag != IO_REPARSE_TAG_SYMLINK) @throw [OFStatItemFailedException - exceptionWithPath: path]; + exceptionWithPath: path + errNo: 0]; #define slrb buffer.data.SymbolicLinkReparseBuffer tmp = slrb.PathBuffer + (slrb.SubstituteNameOffset / sizeof(wchar_t)); Index: src/OFPlugin.m ================================================================== --- src/OFPlugin.m +++ src/OFPlugin.m @@ -26,10 +26,11 @@ #import "OFPlugin.h" #import "OFString.h" #import "OFLocalization.h" #import "OFInitializationFailedException.h" +#import "OFOpenItemFailedException.h" typedef OFPlugin *(*init_plugin_t)(void); of_plugin_handle_t of_dlopen(OFString *path, int flags) @@ -74,12 +75,13 @@ OFPlugin *plugin; path = [path stringByAppendingString: @PLUGIN_SUFFIX]; if ((handle = of_dlopen(path, OF_RTLD_LAZY)) == NULL) - @throw [OFInitializationFailedException - exceptionWithClass: self]; + @throw [OFOpenItemFailedException exceptionWithPath: path + mode: nil + errNo: 0]; objc_autoreleasePoolPop(pool); initPlugin = (init_plugin_t)(uintptr_t)of_dlsym(handle, "init_plugin"); if (initPlugin == (init_plugin_t)0 || (plugin = initPlugin()) == nil) { @@ -95,15 +97,16 @@ - init { if (object_getClass(self) == [OFPlugin class]) { @try { [self doesNotRecognizeSelector: _cmd]; - abort(); } @catch (id e) { [self release]; @throw e; } + + abort(); } return [super init]; } Index: src/OFProcess.m ================================================================== --- src/OFProcess.m +++ src/OFProcess.m @@ -471,11 +471,12 @@ _atEndOfStream = true; return 0; } @throw [OFReadFailedException exceptionWithObject: self - requestedLength: length]; + requestedLength: length + errNo: EIO]; } #endif if (ret == 0) _atEndOfStream = true; @@ -506,11 +507,11 @@ if (_writePipe[1] == NULL) @throw [OFNotOpenException exceptionWithObject: self]; if (!WriteFile(_writePipe[1], buffer, (DWORD)length, &ret, NULL) || ret != (DWORD)length) { - int errNo = 0; + int errNo = EIO; if (GetLastError() == ERROR_BROKEN_PIPE) errNo = EPIPE; @throw [OFWriteFailedException exceptionWithObject: self Index: src/OFStdIOStream.m ================================================================== --- src/OFStdIOStream.m +++ src/OFStdIOStream.m @@ -206,11 +206,12 @@ if (length > LONG_MAX) @throw [OFOutOfRangeException exception]; if ((ret = Read(_handle, buffer, length)) < 0) @throw [OFReadFailedException exceptionWithObject: self - requestedLength: length]; + requestedLength: length + errNo: EIO]; #endif if (ret == 0) _atEndOfStream = true; @@ -248,11 +249,12 @@ if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if (Write(_handle, (void *)buffer, length) != (LONG)length) @throw [OFWriteFailedException exceptionWithObject: self - requestedLength: length]; + requestedLength: length + errNo: EIO]; #endif } #if !defined(OF_WINDOWS) && !defined(OF_MORPHOS) - (int)fileDescriptorForReading Index: src/OFStdIOStream_Win32Console.m ================================================================== --- src/OFStdIOStream_Win32Console.m +++ src/OFStdIOStream_Win32Console.m @@ -41,10 +41,11 @@ #define OF_STDIO_STREAM_WIN32_CONSOLE_M #include "config.h" #include +#include #import "OFStdIOStream_Win32Console.h" #import "OFStdIOStream+Private.h" #import "OFString.h" #import "OFDataArray.h" @@ -120,11 +121,12 @@ if (!ReadConsoleW(_handle, UTF16, (DWORD)length, &UTF16Len, NULL)) @throw [OFReadFailedException exceptionWithObject: self - requestedLength: length * 2]; + requestedLength: length * 2 + errNo: EIO]; if (UTF16Len > 0 && _incompleteUTF16Surrogate != 0) { of_unichar_t c = (((_incompleteUTF16Surrogate & 0x3FF) << 10) | (UTF16[0] & 0x3FF)) + 0x10000; @@ -271,11 +273,12 @@ if (!WriteConsoleW(_handle, UTF16, UTF16Len, &written, NULL) || written != UTF16Len) @throw [OFWriteFailedException exceptionWithObject: self - requestedLength: UTF16Len * 2]; + requestedLength: UTF16Len * 2 + errNo: EIO]; _incompleteUTF8SurrogateLen = 0; i += toCopy; } @@ -322,11 +325,12 @@ if (!WriteConsoleW(_handle, tmp, (DWORD)j, &written, NULL) || written != j) @throw [OFWriteFailedException exceptionWithObject: self - requestedLength: j * 2]; + requestedLength: j * 2 + errNo: EIO]; } @finally { [self freeMemory: tmp]; } } @end Index: src/OFTCPSocket+SOCKS5.m ================================================================== --- src/OFTCPSocket+SOCKS5.m +++ src/OFTCPSocket+SOCKS5.m @@ -13,10 +13,12 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" + +#include #import "OFTCPSocket+SOCKS5.h" #import "OFDataArray.h" #import "OFConnectionFailedException.h" @@ -74,13 +76,15 @@ recv_exact(self, _socket, reply, 2); if (reply[0] != 5 || reply[1] != 0) { [self close]; - @throw [OFConnectionFailedException exceptionWithHost: host - port: port - socket: self]; + @throw [OFConnectionFailedException + exceptionWithHost: host + port: port + socket: self + errNo: EPROTONOSUPPORT]; } /* CONNECT request */ pool = objc_autoreleasePoolPush(); connectRequest = [OFDataArray dataArray]; @@ -106,15 +110,55 @@ objc_autoreleasePoolPop(pool); recv_exact(self, _socket, reply, 4); - if (reply[0] != 5 || reply[1] != 0 || reply[2] != 0) { + if (reply[0] != 5 || reply[2] != 0) { + [self close]; + @throw [OFConnectionFailedException + exceptionWithHost: host + port: port + socket: self + errNo: EPROTONOSUPPORT]; + } + + if (reply[1] != 0) { + int errNo; + [self close]; + + switch (reply[1]) { + case 0x02: + errNo = EACCES; + break; + case 0x03: + errNo = ENETUNREACH; + break; + case 0x04: + errNo = EHOSTUNREACH; + break; + case 0x05: + errNo = ECONNREFUSED; + break; + case 0x06: + errNo = ETIMEDOUT; + break; + case 0x07: + errNo = EPROTONOSUPPORT; + break; + case 0x08: + errNo = EAFNOSUPPORT; + break; + default: + errNo = 0; + break; + } + @throw [OFConnectionFailedException exceptionWithHost: host port: port - socket: self]; + socket: self + errNo: errNo]; } /* Skip the rest of the reply */ switch (reply[3]) { case 1: /* IPv4 */ @@ -127,13 +171,15 @@ case 4: /* IPv6 */ recv_exact(self, _socket, reply, 16); break; default: [self close]; - @throw [OFConnectionFailedException exceptionWithHost: host - port: port - socket: self]; + @throw [OFConnectionFailedException + exceptionWithHost: host + port: port + socket: self + errNo: EPROTONOSUPPORT]; } recv_exact(self, _socket, reply, 2); } @end Index: src/exceptions/OFChangePermissionsFailedException.m ================================================================== --- src/exceptions/OFChangePermissionsFailedException.m +++ src/exceptions/OFChangePermissionsFailedException.m @@ -26,11 +26,11 @@ { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithPath: (OFString *)path - permissions: (mode_t)permissions + permissions: (uint16_t)permissions errNo: (int)errNo { return [[[self alloc] initWithPath: path permissions: permissions errNo: errNo] autorelease]; @@ -40,11 +40,11 @@ { OF_INVALID_INIT_METHOD } - initWithPath: (OFString *)path - permissions: (mode_t)permissions + permissions: (uint16_t)permissions errNo: (int)errNo { self = [super init]; @try { Index: src/exceptions/OFConnectionFailedException.h ================================================================== --- src/exceptions/OFConnectionFailedException.h +++ src/exceptions/OFConnectionFailedException.h @@ -62,22 +62,10 @@ * @brief Creates a new, autoreleased connection failed exception. * * @param host The host to which the connection failed * @param port The port on the host to which the connection failed * @param socket The socket which could not connect - * @return A new, autoreleased connection failed exception - */ -+ (instancetype)exceptionWithHost: (OFString *)host - port: (uint16_t)port - socket: (id)socket; - -/*! - * @brief Creates a new, autoreleased connection failed exception. - * - * @param host The host to which the connection failed - * @param port The port on the host to which the connection failed - * @param socket The socket which could not connect * @param errNo The errno of the error that occurred * @return A new, autoreleased connection failed exception */ + (instancetype)exceptionWithHost: (OFString *)host port: (uint16_t)port @@ -84,22 +72,10 @@ socket: (id)socket errNo: (int)errNo; - init OF_UNAVAILABLE; -/*! - * @brief Initializes an already allocated connection failed exception. - * - * @param host The host to which the connection failed - * @param port The port on the host to which the connection failed - * @param socket The socket which could not connect - * @return An initialized connection failed exception - */ -- initWithHost: (OFString *)host - port: (uint16_t)port - socket: (id)socket; - /*! * @brief Initializes an already allocated connection failed exception. * * @param host The host to which the connection failed * @param port The port on the host to which the connection failed Index: src/exceptions/OFConnectionFailedException.m ================================================================== --- src/exceptions/OFConnectionFailedException.m +++ src/exceptions/OFConnectionFailedException.m @@ -30,19 +30,10 @@ } + (instancetype)exceptionWithHost: (OFString *)host port: (uint16_t)port socket: (id)socket -{ - return [[[self alloc] initWithHost: host - port: port - socket: socket] autorelease]; -} - -+ (instancetype)exceptionWithHost: (OFString *)host - port: (uint16_t)port - socket: (id)socket errNo: (int)errNo { return [[[self alloc] initWithHost: host port: port socket: socket @@ -52,20 +43,10 @@ - init { OF_INVALID_INIT_METHOD } -- initWithHost: (OFString *)host - port: (uint16_t)port - socket: (id)socket -{ - return [self initWithHost: host - port: port - socket: socket - errNo: 0]; -} - - initWithHost: (OFString *)host port: (uint16_t)port socket: (id)socket errNo: (int)errNo { @@ -92,17 +73,11 @@ [super dealloc]; } - (OFString *)description { - if (_errNo != 0) - return [OFString stringWithFormat: - @"A connection to %@ on port %" @PRIu16 @" could not be " - @"established in socket of type %@: %@", - _host, _port, [_socket class], of_strerror(_errNo)]; - else - return [OFString stringWithFormat: - @"A connection to %@ on port %" @PRIu16 @" could not be " - @"established in socket of type %@!", - _host, _port, [_socket class]]; + return [OFString stringWithFormat: + @"A connection to %@ on port %" @PRIu16 @" could not be " + @"established in socket of type %@: %@", + _host, _port, [_socket class], of_strerror(_errNo)]; } @end Index: src/exceptions/OFCreateSymbolicLinkFailedException.h ================================================================== --- src/exceptions/OFCreateSymbolicLinkFailedException.h +++ src/exceptions/OFCreateSymbolicLinkFailedException.h @@ -49,20 +49,10 @@ + (instancetype)exception OF_UNAVAILABLE; /*! * @brief Creates a new, autoreleased create symbolic link failed exception. * - * @param sourcePath The source for the symbolic link - * @param destinationPath The destination for the symbolic link - * @return A new, autoreleased create symbolic link failed exception - */ -+ (instancetype)exceptionWithSourcePath: (OFString *)sourcePath - destinationPath: (OFString *)destinationPath; - -/*! - * @brief Creates a new, autoreleased create symbolic link failed exception. - * * @param sourcePath The source for the symbolic link * @param destinationPath The destination for the symbolic link * @param errNo The errno of the error that occurred * @return A new, autoreleased create symbolic link failed exception */ @@ -70,21 +60,10 @@ destinationPath: (OFString *)destinationPath errNo: (int)errNo; - init OF_UNAVAILABLE; -/*! - * @brief Initializes an already allocated create symbolic link failed - * exception. - * - * @param sourcePath The source for the symbolic link - * @param destinationPath The destination for the symbolic link - * @return An initialized create symbolic link failed exception - */ -- initWithSourcePath: (OFString *)sourcePath - destinationPath: (OFString *)destinationPath; - /*! * @brief Initializes an already allocated create symbolic link failed * exception. * * @param sourcePath The source for the symbolic link Index: src/exceptions/OFCreateSymbolicLinkFailedException.m ================================================================== --- src/exceptions/OFCreateSymbolicLinkFailedException.m +++ src/exceptions/OFCreateSymbolicLinkFailedException.m @@ -28,17 +28,10 @@ OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSourcePath: (OFString *)sourcePath destinationPath: (OFString *)destinationPath -{ - return [[[self alloc] initWithSourcePath: sourcePath - destinationPath: destinationPath] autorelease]; -} - -+ (instancetype)exceptionWithSourcePath: (OFString *)sourcePath - destinationPath: (OFString *)destinationPath errNo: (int)errNo { return [[[self alloc] initWithSourcePath: sourcePath destinationPath: destinationPath errNo: errNo] autorelease]; @@ -47,18 +40,10 @@ - init { OF_INVALID_INIT_METHOD } -- initWithSourcePath: (OFString *)sourcePath - destinationPath: (OFString *)destinationPath -{ - return [self initWithSourcePath: sourcePath - destinationPath: destinationPath - errNo: 0]; -} - - initWithSourcePath: (OFString *)sourcePath destinationPath: (OFString *)destinationPath errNo: (int)errNo { self = [super init]; @@ -83,16 +68,10 @@ [super dealloc]; } - (OFString *)description { - if (_errNo != 0) - return [OFString stringWithFormat: - @"Failed to create symbolic link %@ with destination " - @"%@: %@", _destinationPath, _sourcePath, - of_strerror(_errNo)]; - else - return [OFString stringWithFormat: - @"Failed to create symbolic link %@ with destination %@!", - _destinationPath, _sourcePath]; + return [OFString stringWithFormat: + @"Failed to create symbolic link %@ with destination %@: %@", + _destinationPath, _sourcePath, of_strerror(_errNo)]; } @end Index: src/exceptions/OFException.h ================================================================== --- src/exceptions/OFException.h +++ src/exceptions/OFException.h @@ -130,11 +130,10 @@ # define EUSERS WSAEUSERS # endif # ifndef EWOULDBLOCK # define EWOULDBLOCK WSAEWOULDBLOCK # endif -extern int of_wsaerr_to_errno(int); #endif /*! * @class OFException OFException.h ObjFW/OFException.h * Index: src/exceptions/OFException.m ================================================================== --- src/exceptions/OFException.m +++ src/exceptions/OFException.m @@ -102,10 +102,13 @@ OFString *ret; #ifdef HAVE_STRERROR_R char buffer[256]; #endif + if (errNo == 0) + return @"Unknown error"; + #ifdef OF_WINDOWS /* * These were translated from WSAE* errors to errno and thus Win32's * strerror_r() does not know about them. * Index: src/exceptions/OFLinkFailedException.h ================================================================== --- src/exceptions/OFLinkFailedException.h +++ src/exceptions/OFLinkFailedException.h @@ -48,20 +48,10 @@ + (instancetype)exception OF_UNAVAILABLE; /*! * @brief Creates a new, autoreleased link failed exception. * - * @param sourcePath The source for the link - * @param destinationPath The destination for the link - * @return A new, autoreleased link failed exception - */ -+ (instancetype)exceptionWithSourcePath: (OFString *)sourcePath - destinationPath: (OFString *)destinationPath; - -/*! - * @brief Creates a new, autoreleased link failed exception. - * * @param sourcePath The source for the link * @param destinationPath The destination for the link * @param errNo The errno of the error that occurred * @return A new, autoreleased link failed exception */ @@ -69,20 +59,10 @@ destinationPath: (OFString *)destinationPath errNo: (int)errNo; - init OF_UNAVAILABLE; -/*! - * @brief Initializes an already allocated link failed exception. - * - * @param sourcePath The source for the link - * @param destinationPath The destination for the link - * @return An initialized link failed exception - */ -- initWithSourcePath: (OFString *)sourcePath - destinationPath: (OFString *)destinationPath; - /*! * @brief Initializes an already allocated link failed exception. * * @param sourcePath The source for the link * @param destinationPath The destination for the link Index: src/exceptions/OFLinkFailedException.m ================================================================== --- src/exceptions/OFLinkFailedException.m +++ src/exceptions/OFLinkFailedException.m @@ -28,17 +28,10 @@ OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSourcePath: (OFString *)sourcePath destinationPath: (OFString *)destinationPath -{ - return [[[self alloc] initWithSourcePath: sourcePath - destinationPath: destinationPath] autorelease]; -} - -+ (instancetype)exceptionWithSourcePath: (OFString *)sourcePath - destinationPath: (OFString *)destinationPath errNo: (int)errNo { return [[[self alloc] initWithSourcePath: sourcePath destinationPath: destinationPath errNo: errNo] autorelease]; @@ -47,18 +40,10 @@ - init { OF_INVALID_INIT_METHOD } -- initWithSourcePath: (OFString *)sourcePath - destinationPath: (OFString *)destinationPath -{ - return [self initWithSourcePath: sourcePath - destinationPath: destinationPath - errNo: 0]; -} - - initWithSourcePath: (OFString *)sourcePath destinationPath: (OFString *)destinationPath errNo: (int)errNo { self = [super init]; @@ -83,15 +68,9 @@ [super dealloc]; } - (OFString *)description { - if (_errNo != 0) - return [OFString stringWithFormat: - @"Failed to link file %@ to %@: %@", - _sourcePath, _destinationPath, of_strerror(_errNo)]; - else - return [OFString stringWithFormat: - @"Failed to link file %@ to %@!", - _sourcePath, _destinationPath]; + return [OFString stringWithFormat: @"Failed to link file %@ to %@: %@", + _sourcePath, _destinationPath, of_strerror(_errNo)]; } @end Index: src/exceptions/OFOpenItemFailedException.h ================================================================== --- src/exceptions/OFOpenItemFailedException.h +++ src/exceptions/OFOpenItemFailedException.h @@ -48,38 +48,10 @@ + (instancetype)exception OF_UNAVAILABLE; /*! * @brief Creates a new, autoreleased open item failed exception. * - * @param path A string with the path of the item tried to open - * @return A new, autoreleased open item failed exception - */ -+ (instancetype)exceptionWithPath: (OFString *)path; - -/*! - * @brief Creates a new, autoreleased open item failed exception. - * - * @param path A string with the path of the item tried to open - * @param mode A string with the mode in which the item should have been opened - * @return A new, autoreleased open item failed exception - */ -+ (instancetype)exceptionWithPath: (OFString *)path - mode: (nullable OFString *)mode; - -/*! - * @brief Creates a new, autoreleased open item failed exception. - * - * @param path A string with the path of the item tried to open - * @param errNo The errno of the error that occurred - * @return A new, autoreleased open item failed exception - */ -+ (instancetype)exceptionWithPath: (OFString *)path - errNo: (int)errNo; - -/*! - * @brief Creates a new, autoreleased open item failed exception. - * * @param path A string with the path of the item tried to open * @param mode A string with the mode in which the item should have been opened * @param errNo The errno of the error that occurred * @return A new, autoreleased open item failed exception */ @@ -87,38 +59,10 @@ mode: (nullable OFString *)mode errNo: (int)errNo; - init OF_UNAVAILABLE; -/*! - * @brief Initializes an already allocated open item failed exception. - * - * @param path A string with the path of the item which could not be opened - * @return An initialized open item failed exception - */ -- initWithPath: (OFString *)path; - -/*! - * @brief Initializes an already allocated open item failed exception. - * - * @param path A string with the path of the item which could not be opened - * @param mode A string with the mode in which the item should have been opened - * @return An initialized open item failed exception - */ -- initWithPath: (OFString *)path - mode: (nullable OFString *)mode; - -/*! - * @brief Initializes an already allocated open item failed exception. - * - * @param path A string with the path of the item which could not be opened - * @param errNo The errno of the error that occurred - * @return An initialized open item failed exception - */ -- initWithPath: (OFString *)path - errNo: (int)errNo; - /*! * @brief Initializes an already allocated open item failed exception. * * @param path A string with the path of the item which could not be opened * @param mode A string with the mode in which the item should have been opened Index: src/exceptions/OFOpenItemFailedException.m ================================================================== --- src/exceptions/OFOpenItemFailedException.m +++ src/exceptions/OFOpenItemFailedException.m @@ -25,29 +25,10 @@ + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } -+ (instancetype)exceptionWithPath: (OFString *)path -{ - return [[[self alloc] initWithPath: path] autorelease]; -} - -+ (instancetype)exceptionWithPath: (OFString *)path - mode: (OFString *)mode -{ - return [[[self alloc] initWithPath: path - mode: mode] autorelease]; -} - -+ (instancetype)exceptionWithPath: (OFString *)path - errNo: (int)errNo -{ - return [[[self alloc] initWithPath: path - errNo: errNo] autorelease]; -} - + (instancetype)exceptionWithPath: (OFString *)path mode: (OFString *)mode errNo: (int)errNo { return [[[self alloc] initWithPath: path @@ -58,33 +39,10 @@ - init { OF_INVALID_INIT_METHOD } -- initWithPath: (OFString *)path -{ - return [self initWithPath: path - mode: nil - errNo: 0]; -} - -- initWithPath: (OFString *)path - mode: (OFString *)mode -{ - return [self initWithPath: path - mode: mode - errNo: 0]; -} - -- initWithPath: (OFString *)path - errNo: (int)errNo -{ - return [self initWithPath: path - mode: nil - errNo: errNo]; -} - - initWithPath: (OFString *)path mode: (OFString *)mode errNo: (int)errNo { self = [super init]; @@ -109,25 +67,14 @@ [super dealloc]; } - (OFString *)description { - if (_mode != nil) { - if (_errNo != 0) - return [OFString stringWithFormat: - @"Failed to open item %@ with mode %@: %@", - _path, _mode, of_strerror(_errNo)]; - else - return [OFString stringWithFormat: - @"Failed to open item %@ with mode %@!", - _path, _mode]; - } else { - if (_errNo != 0) - return [OFString stringWithFormat: - @"Failed to open item %@: %@", - _path, of_strerror(_errNo)]; - else - return [OFString stringWithFormat: - @"Failed to open item %@!", _path]; - } + if (_mode != nil) + return [OFString stringWithFormat: + @"Failed to open item %@ with mode %@: %@", + _path, _mode, of_strerror(_errNo)]; + else + return [OFString stringWithFormat: + @"Failed to open item %@: %@", _path, of_strerror(_errNo)]; } @end Index: src/exceptions/OFReadFailedException.m ================================================================== --- src/exceptions/OFReadFailedException.m +++ src/exceptions/OFReadFailedException.m @@ -20,15 +20,10 @@ #import "OFString.h" @implementation OFReadFailedException - (OFString *)description { - if (_errNo != 0) - return [OFString stringWithFormat: - @"Failed to read %zu bytes from an object of type %@: %@", - _requestedLength, [_object class], of_strerror(_errNo)]; - else - return [OFString stringWithFormat: - @"Failed to read %zu bytes from an object of type %@!", - _requestedLength, [_object class]]; + return [OFString stringWithFormat: + @"Failed to read %zu bytes from an object of type %@: %@", + _requestedLength, [_object class], of_strerror(_errNo)]; } @end Index: src/exceptions/OFReadOrWriteFailedException.h ================================================================== --- src/exceptions/OFReadOrWriteFailedException.h +++ src/exceptions/OFReadOrWriteFailedException.h @@ -53,41 +53,19 @@ * @brief Creates a new, autoreleased read or write failed exception. * * @param object The object from which reading or to which writing failed * @param requestedLength The requested length of the data that could not be * read / written - * @return A new, autoreleased read or write failed exception - */ -+ (instancetype)exceptionWithObject: (id)object - requestedLength: (size_t)requestedLength; - -/*! - * @brief Creates a new, autoreleased read or write failed exception. - * - * @param object The object from which reading or to which writing failed - * @param requestedLength The requested length of the data that could not be - * read / written * @param errNo The errno of the error that occurred * @return A new, autoreleased read or write failed exception */ + (instancetype)exceptionWithObject: (id)object requestedLength: (size_t)requestedLength errNo: (int)errNo; - init OF_UNAVAILABLE; -/*! - * @brief Initializes an already allocated read or write failed exception. - * - * @param object The object from which reading or to which writing failed - * @param requestedLength The requested length of the data that could not be - * read / written - * @return A new open file failed exception - */ -- initWithObject: (id)object - requestedLength: (size_t)requestedLength; - /*! * @brief Initializes an already allocated read or write failed exception. * * @param object The object from which reading or to which writing failed * @param requestedLength The requested length of the data that could not be Index: src/exceptions/OFReadOrWriteFailedException.m ================================================================== --- src/exceptions/OFReadOrWriteFailedException.m +++ src/exceptions/OFReadOrWriteFailedException.m @@ -28,17 +28,10 @@ OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithObject: (id)object requestedLength: (size_t)requestedLength -{ - return [[[self alloc] initWithObject: object - requestedLength: requestedLength] autorelease]; -} - -+ (instancetype)exceptionWithObject: (id)object - requestedLength: (size_t)requestedLength errNo: (int)errNo { return [[[self alloc] initWithObject: object requestedLength: requestedLength errNo: errNo] autorelease]; @@ -47,18 +40,10 @@ - init { OF_INVALID_INIT_METHOD } -- initWithObject: (id)object - requestedLength: (size_t)requestedLength -{ - return [self initWithObject: object - requestedLength: requestedLength - errNo: 0]; -} - - initWithObject: (id)object requestedLength: (size_t)requestedLength errNo: (int)errNo { self = [super init]; @@ -77,17 +62,11 @@ [super dealloc]; } - (OFString *)description { - if (_errNo != 0) - return [OFString stringWithFormat: - @"Failed to read or write %zu bytes from / to an object of " - @"type %@: %@", - _requestedLength, [_object class], of_strerror(_errNo)]; - else - return [OFString stringWithFormat: - @"Failed to read or write %zu bytes from / to an object of " - @"type %@!", - _requestedLength, [_object class]]; + return [OFString stringWithFormat: + @"Failed to read or write %zu bytes from / to an object of type " + @"%@: %@", + _requestedLength, [_object class], of_strerror(_errNo)]; } @end Index: src/exceptions/OFSeekFailedException.h ================================================================== --- src/exceptions/OFSeekFailedException.h +++ src/exceptions/OFSeekFailedException.h @@ -58,22 +58,10 @@ * @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 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 * @param errNo The errno of the error that occurred * @return A new, autoreleased seek failed exception */ + (instancetype)exceptionWithStream: (OFSeekableStream *)stream offset: (of_offset_t)offset @@ -80,22 +68,10 @@ whence: (int)whence errNo: (int)errNo; - init OF_UNAVAILABLE; -/*! - * @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 Initializes an already allocated seek failed exception. * * @param stream The stream for which seeking failed * @param offset The offset to which seeking failed Index: src/exceptions/OFSeekFailedException.m ================================================================== --- src/exceptions/OFSeekFailedException.m +++ src/exceptions/OFSeekFailedException.m @@ -30,19 +30,10 @@ } + (instancetype)exceptionWithStream: (OFSeekableStream *)stream offset: (of_offset_t)offset whence: (int)whence -{ - return [[[self alloc] initWithStream: stream - offset: offset - whence: whence] autorelease]; -} - -+ (instancetype)exceptionWithStream: (OFSeekableStream *)stream - offset: (of_offset_t)offset - whence: (int)whence errNo: (int)errNo { return [[[self alloc] initWithStream: stream offset: offset whence: whence @@ -52,20 +43,10 @@ - init { OF_INVALID_INIT_METHOD } -- initWithStream: (OFSeekableStream *)stream - offset: (of_offset_t)offset - whence: (int)whence -{ - return [self initWithStream: stream - offset: offset - whence: whence - errNo: 0]; -} - - initWithStream: (OFSeekableStream *)stream offset: (of_offset_t)offset whence: (int)whence errNo: (int)errNo { @@ -86,14 +67,10 @@ [super dealloc]; } - (OFString *)description { - if (_errNo != 0) - return [OFString stringWithFormat: - @"Seeking failed in stream of type %@: %@", - [_stream class], of_strerror(_errNo)]; - else - return [OFString stringWithFormat: - @"Seeking failed in stream of type %@!", [_stream class]]; + return [OFString stringWithFormat: + @"Seeking failed in stream of type %@: %@", + [_stream class], of_strerror(_errNo)]; } @end Index: src/exceptions/OFStatItemFailedException.h ================================================================== --- src/exceptions/OFStatItemFailedException.h +++ src/exceptions/OFStatItemFailedException.h @@ -45,36 +45,18 @@ /*! * @brief Creates a new, autoreleased stat item failed exception. * * @param path A string with the path of the item whose status could not be * retrieved - * @return A new, autoreleased stat item failed exception - */ -+ (instancetype)exceptionWithPath: (OFString *)path; - -/*! - * @brief Creates a new, autoreleased stat item failed exception. - * - * @param path A string with the path of the item whose status could not be - * retrieved * @param errNo The errno of the error that occurred * @return A new, autoreleased stat item failed exception */ + (instancetype)exceptionWithPath: (OFString *)path errNo: (int)errNo; - init OF_UNAVAILABLE; -/*! - * @brief Initializes an already allocated stat item failed exception. - * - * @param path A string with the path of the item whose status could not be - * retrieved - * @return An initialized stat item failed exception - */ -- initWithPath: (OFString *)path; - /*! * @brief Initializes an already allocated stat item failed exception. * * @param path A string with the path of the item whose status could not be * retrieved Index: src/exceptions/OFStatItemFailedException.m ================================================================== --- src/exceptions/OFStatItemFailedException.m +++ src/exceptions/OFStatItemFailedException.m @@ -25,15 +25,10 @@ + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } -+ (instancetype)exceptionWithPath: (OFString *)path -{ - return [[[self alloc] initWithPath: path] autorelease]; -} - + (instancetype)exceptionWithPath: (OFString *)path errNo: (int)errNo { return [[[self alloc] initWithPath: path errNo: errNo] autorelease]; @@ -42,16 +37,10 @@ - init { OF_INVALID_INIT_METHOD } -- initWithPath: (OFString *)path -{ - return [self initWithPath: path - errNo: 0]; -} - - initWithPath: (OFString *)path errNo: (int)errNo { self = [super init]; @@ -73,13 +62,9 @@ [super dealloc]; } - (OFString *)description { - if (_errNo != 0) - return [OFString stringWithFormat: - @"Failed to stat item %@: %@", _path, of_strerror(_errNo)]; - else - return [OFString stringWithFormat: - @"Failed to stat item %@!", _path]; + return [OFString stringWithFormat: + @"Failed to stat item %@: %@", _path, of_strerror(_errNo)]; } @end Index: src/exceptions/OFWriteFailedException.m ================================================================== --- src/exceptions/OFWriteFailedException.m +++ src/exceptions/OFWriteFailedException.m @@ -20,15 +20,10 @@ #import "OFString.h" @implementation OFWriteFailedException - (OFString *)description { - if (_errNo != 0) - return [OFString stringWithFormat: - @"Failed to write %zu bytes to an object of type %@: %@", - _requestedLength, [_object class], of_strerror(_errNo)]; - else - return [OFString stringWithFormat: - @"Failed to write %zu bytes to an object of type %@!", - _requestedLength, [_object class]]; + return [OFString stringWithFormat: + @"Failed to write %zu bytes to an object of type %@: %@", + _requestedLength, [_object class], of_strerror(_errNo)]; } @end