Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -270,12 +270,12 @@ 4B55A100133ABEA900B58A93 /* OFThreadJoinFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55A0FA133ABEA900B58A93 /* OFThreadJoinFailedException.m */; }; 4B55A101133ABEA900B58A93 /* OFThreadStartFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B55A0FB133ABEA900B58A93 /* OFThreadStartFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B55A102133ABEA900B58A93 /* OFThreadStartFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55A0FC133ABEA900B58A93 /* OFThreadStartFailedException.m */; }; 4B55A103133ABEA900B58A93 /* OFThreadStillRunningException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B55A0FD133ABEA900B58A93 /* OFThreadStillRunningException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B55A104133ABEA900B58A93 /* OFThreadStillRunningException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55A0FE133ABEA900B58A93 /* OFThreadStillRunningException.m */; }; - 4B55A10A133AC05100B58A93 /* OFOpenFileFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B55A107133AC05100B58A93 /* OFOpenFileFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 4B55A10B133AC05100B58A93 /* OFOpenFileFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55A108133AC05100B58A93 /* OFOpenFileFailedException.m */; }; + 4B55A10A133AC05100B58A93 /* OFOpenItemFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B55A107133AC05100B58A93 /* OFOpenItemFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4B55A10B133AC05100B58A93 /* OFOpenItemFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55A108133AC05100B58A93 /* OFOpenItemFailedException.m */; }; 4B55A112133AC24600B58A93 /* OFReadFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B55A10C133AC24500B58A93 /* OFReadFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B55A113133AC24600B58A93 /* OFReadFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55A10D133AC24500B58A93 /* OFReadFailedException.m */; }; 4B55A114133AC24600B58A93 /* OFReadOrWriteFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B55A10E133AC24500B58A93 /* OFReadOrWriteFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B55A115133AC24600B58A93 /* OFReadOrWriteFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55A10F133AC24500B58A93 /* OFReadOrWriteFailedException.m */; }; 4B55A116133AC24600B58A93 /* OFWriteFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B55A110133AC24500B58A93 /* OFWriteFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -694,12 +694,12 @@ 4B55A0FA133ABEA900B58A93 /* OFThreadJoinFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFThreadJoinFailedException.m; path = src/exceptions/OFThreadJoinFailedException.m; sourceTree = ""; }; 4B55A0FB133ABEA900B58A93 /* OFThreadStartFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFThreadStartFailedException.h; path = src/exceptions/OFThreadStartFailedException.h; sourceTree = ""; }; 4B55A0FC133ABEA900B58A93 /* OFThreadStartFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFThreadStartFailedException.m; path = src/exceptions/OFThreadStartFailedException.m; sourceTree = ""; }; 4B55A0FD133ABEA900B58A93 /* OFThreadStillRunningException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFThreadStillRunningException.h; path = src/exceptions/OFThreadStillRunningException.h; sourceTree = ""; }; 4B55A0FE133ABEA900B58A93 /* OFThreadStillRunningException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFThreadStillRunningException.m; path = src/exceptions/OFThreadStillRunningException.m; sourceTree = ""; }; - 4B55A107133AC05100B58A93 /* OFOpenFileFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFOpenFileFailedException.h; path = src/exceptions/OFOpenFileFailedException.h; sourceTree = ""; }; - 4B55A108133AC05100B58A93 /* OFOpenFileFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFOpenFileFailedException.m; path = src/exceptions/OFOpenFileFailedException.m; sourceTree = ""; }; + 4B55A107133AC05100B58A93 /* OFOpenItemFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFOpenItemFailedException.h; path = src/exceptions/OFOpenItemFailedException.h; sourceTree = ""; }; + 4B55A108133AC05100B58A93 /* OFOpenItemFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFOpenItemFailedException.m; path = src/exceptions/OFOpenItemFailedException.m; sourceTree = ""; }; 4B55A10C133AC24500B58A93 /* OFReadFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFReadFailedException.h; path = src/exceptions/OFReadFailedException.h; sourceTree = ""; }; 4B55A10D133AC24500B58A93 /* OFReadFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFReadFailedException.m; path = src/exceptions/OFReadFailedException.m; sourceTree = ""; }; 4B55A10E133AC24500B58A93 /* OFReadOrWriteFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFReadOrWriteFailedException.h; path = src/exceptions/OFReadOrWriteFailedException.h; sourceTree = ""; }; 4B55A10F133AC24500B58A93 /* OFReadOrWriteFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFReadOrWriteFailedException.m; path = src/exceptions/OFReadOrWriteFailedException.m; sourceTree = ""; }; 4B55A110133AC24500B58A93 /* OFWriteFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFWriteFailedException.h; path = src/exceptions/OFWriteFailedException.h; sourceTree = ""; }; @@ -1091,12 +1091,12 @@ 4B7DD5841894358400990FD6 /* OFMoveItemFailedException.m */, 4B90B789133AD46700BD33CB /* OFNotConnectedException.h */, 4B90B78A133AD46700BD33CB /* OFNotConnectedException.m */, 4B17FF75133A2B18003E6DCD /* OFNotImplementedException.h */, 4B17FF76133A2B18003E6DCD /* OFNotImplementedException.m */, - 4B55A107133AC05100B58A93 /* OFOpenFileFailedException.h */, - 4B55A108133AC05100B58A93 /* OFOpenFileFailedException.m */, + 4B55A107133AC05100B58A93 /* OFOpenItemFailedException.h */, + 4B55A108133AC05100B58A93 /* OFOpenItemFailedException.m */, 4B17FF81133A2DFB003E6DCD /* OFOutOfMemoryException.h */, 4B17FF82133A2DFB003E6DCD /* OFOutOfMemoryException.m */, 4B17FF79133A2C14003E6DCD /* OFOutOfRangeException.h */, 4B17FF7A133A2C15003E6DCD /* OFOutOfRangeException.m */, 4B55A10C133AC24500B58A93 /* OFReadFailedException.h */, @@ -1739,11 +1739,11 @@ 4B17FFA1133A3335003E6DCD /* OFMalformedXMLException.h in Headers */, 4B17FF8F133A3036003E6DCD /* OFMemoryNotPartOfObjectException.h in Headers */, 4B7DD5851894358500990FD6 /* OFMoveItemFailedException.h in Headers */, 4B90B78F133AD46700BD33CB /* OFNotConnectedException.h in Headers */, 4B17FF77133A2B18003E6DCD /* OFNotImplementedException.h in Headers */, - 4B55A10A133AC05100B58A93 /* OFOpenFileFailedException.h in Headers */, + 4B55A10A133AC05100B58A93 /* OFOpenItemFailedException.h in Headers */, 4B17FF83133A2DFB003E6DCD /* OFOutOfMemoryException.h in Headers */, 4B17FF7B133A2C15003E6DCD /* OFOutOfRangeException.h in Headers */, 4B55A112133AC24600B58A93 /* OFReadFailedException.h in Headers */, 4B55A114133AC24600B58A93 /* OFReadOrWriteFailedException.h in Headers */, 4BFF3714177E17C100192782 /* OFRemoveItemFailedException.h in Headers */, @@ -2118,11 +2118,11 @@ 4B17FFA2133A3335003E6DCD /* OFMalformedXMLException.m in Sources */, 4B17FF90133A3036003E6DCD /* OFMemoryNotPartOfObjectException.m in Sources */, 4B7DD5861894358500990FD6 /* OFMoveItemFailedException.m in Sources */, 4B90B790133AD46700BD33CB /* OFNotConnectedException.m in Sources */, 4B17FF78133A2B18003E6DCD /* OFNotImplementedException.m in Sources */, - 4B55A10B133AC05100B58A93 /* OFOpenFileFailedException.m in Sources */, + 4B55A10B133AC05100B58A93 /* OFOpenItemFailedException.m in Sources */, 4B17FF84133A2DFB003E6DCD /* OFOutOfMemoryException.m in Sources */, 4B17FF7C133A2C15003E6DCD /* OFOutOfRangeException.m in Sources */, 4B55A113133AC24600B58A93 /* OFReadFailedException.m in Sources */, 4B55A115133AC24600B58A93 /* OFReadOrWriteFailedException.m in Sources */, 4BFF3715177E17C100192782 /* OFRemoveItemFailedException.m in Sources */, Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -75,11 +75,11 @@ #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFLinkFailedException.h" #import "OFLockFailedException.h" #import "OFMoveItemFailedException.h" -#import "OFOpenFileFailedException.h" +#import "OFOpenItemFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFRemoveItemFailedException.h" #import "OFSeekFailedException.h" @@ -392,12 +392,11 @@ DIR *dir; encoding = [OFSystemInfo native8BitEncoding]; if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL) - @throw [OFOpenFileFailedException exceptionWithPath: path - mode: @"r" + @throw [OFOpenItemFailedException exceptionWithPath: path errNo: errno]; # if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS) if (!of_mutex_lock(&mutex)) @throw [OFLockFailedException exception]; @@ -464,12 +463,11 @@ int errNo = 0; if (GetLastError() == ERROR_FILE_NOT_FOUND) errNo = ENOENT; - @throw [OFOpenFileFailedException exceptionWithPath: path - mode: @"r" + @throw [OFOpenItemFailedException exceptionWithPath: path errNo: errNo]; } @try { do { @@ -524,12 +522,11 @@ if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) != 0) /* FIXME: Maybe use another exception? */ - @throw [OFOpenFileFailedException exceptionWithPath: path - mode: @"r" + @throw [OFOpenItemFailedException exceptionWithPath: path errNo: errno]; return s.st_size; } @@ -540,12 +537,11 @@ if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) != 0) /* FIXME: Maybe use another exception? */ - @throw [OFOpenFileFailedException exceptionWithPath: path - mode: @"r" + @throw [OFOpenItemFailedException exceptionWithPath: path errNo: errno]; /* FIXME: We could be more precise on some OSes */ return [OFDate dateWithTimeIntervalSince1970: s.st_atime]; } @@ -557,12 +553,11 @@ if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) != 0) /* FIXME: Maybe use another exception? */ - @throw [OFOpenFileFailedException exceptionWithPath: path - mode: @"r" + @throw [OFOpenItemFailedException exceptionWithPath: path errNo: errno]; /* FIXME: We could be more precise on some OSes */ return [OFDate dateWithTimeIntervalSince1970: s.st_mtime]; } @@ -574,12 +569,11 @@ if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) != 0) /* FIXME: Maybe use another exception? */ - @throw [OFOpenFileFailedException exceptionWithPath: path - mode: @"r" + @throw [OFOpenItemFailedException exceptionWithPath: path errNo: errno]; /* FIXME: We could be more precise on some OSes */ return [OFDate dateWithTimeIntervalSince1970: s.st_ctime]; } @@ -992,12 +986,12 @@ encoding = [OFSystemInfo native8BitEncoding]; length = readlink([path cStringWithEncoding: encoding], destination, PATH_MAX); if (length < 0) - @throw [OFOpenFileFailedException exceptionWithPath: path - mode: @"r" + /* FIXME: Maybe use another exception? */ + @throw [OFOpenItemFailedException exceptionWithPath: path errNo: errno]; return [OFString stringWithCString: destination encoding: encoding length: length]; @@ -1030,11 +1024,11 @@ native8BitEncoding]], flags, DEFAULT_MODE)) == -1) #else if ((_fd = open([path cStringWithEncoding: [OFSystemInfo native8BitEncoding]], flags, DEFAULT_MODE)) == -1) #endif - @throw [OFOpenFileFailedException + @throw [OFOpenItemFailedException exceptionWithPath: path mode: mode errNo: errno]; } @catch (id e) { [self release]; Index: src/OFINIFile.m ================================================================== --- src/OFINIFile.m +++ src/OFINIFile.m @@ -24,11 +24,11 @@ #import "OFFile.h" #import "OFINICategory.h" #import "OFINICategory+Private.h" #import "OFInvalidFormatException.h" -#import "OFOpenFileFailedException.h" +#import "OFOpenItemFailedException.h" @interface OFINIFile (OF_PRIVATE_CATEGORY) - (void)OF_parseFile: (OFString*)path encoding: (of_string_encoding_t)encoding; @end @@ -139,11 +139,11 @@ OFString *line; @try { file = [OFFile fileWithPath: path mode: @"r"]; - } @catch (OFOpenFileFailedException *e) { + } @catch (OFOpenItemFailedException *e) { /* Handle missing file like an empty file */ if ([e errNo] == ENOENT) return; @throw e; Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -47,11 +47,11 @@ #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" -#import "OFOpenFileFailedException.h" +#import "OFOpenItemFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" @@ -828,11 +828,11 @@ /* Make sure the file system is initialized */ [OFFile class]; if (of_stat(path, &st) != 0) - @throw [OFOpenFileFailedException + @throw [OFOpenItemFailedException exceptionWithPath: path mode: @"rb" errNo: errno]; if (st.st_size > SIZE_MAX) Index: src/OFZIPArchive.m ================================================================== --- src/OFZIPArchive.m +++ src/OFZIPArchive.m @@ -30,11 +30,11 @@ #import "OFChecksumFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" -#import "OFOpenFileFailedException.h" +#import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFSeekFailedException.h" #import "OFUnsupportedVersionException.h" @@ -322,11 +322,11 @@ OFZIPArchiveEntry *entry = [_pathToEntryMap objectForKey: path]; OFZIPArchive_LocalFileHeader *localFileHeader; uint64_t offset64; if (entry == nil) - @throw [OFOpenFileFailedException exceptionWithPath: path + @throw [OFOpenItemFailedException exceptionWithPath: path mode: @"rb" errNo: ENOENT]; offset64 = [entry OF_localFileHeaderOffset]; if ((of_offset_t)offset64 != offset64) Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -143,11 +143,11 @@ #import "OFMoveItemFailedException.h" #ifdef OF_HAVE_SOCKETS # import "OFNotConnectedException.h" #endif #import "OFNotImplementedException.h" -#import "OFOpenFileFailedException.h" +#import "OFOpenItemFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFReadOrWriteFailedException.h" #import "OFRemoveItemFailedException.h" Index: src/exceptions/Makefile ================================================================== --- src/exceptions/Makefile +++ src/exceptions/Makefile @@ -24,11 +24,11 @@ OFLockFailedException.m \ OFMalformedXMLException.m \ OFMemoryNotPartOfObjectException.m \ OFMoveItemFailedException.m \ OFNotImplementedException.m \ - OFOpenFileFailedException.m \ + OFOpenItemFailedException.m \ OFOutOfMemoryException.m \ OFOutOfRangeException.m \ OFReadFailedException.m \ OFReadOrWriteFailedException.m \ OFRemoveItemFailedException.m \ DELETED src/exceptions/OFOpenFileFailedException.h Index: src/exceptions/OFOpenFileFailedException.h ================================================================== --- src/exceptions/OFOpenFileFailedException.h +++ src/exceptions/OFOpenFileFailedException.h @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * 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" - -/*! - * @class OFOpenFileFailedException \ - * OFOpenFileFailedException.h ObjFW/OFOpenFileFailedException.h - * - * @brief An exception indicating a file couldn't be opened. - */ -@interface OFOpenFileFailedException: OFException -{ - OFString *_path, *_mode; - int _errNo; -} - -#ifdef OF_HAVE_PROPERTIES -@property (readonly, copy) OFString *path, *mode; -@property (readonly) int errNo; -#endif - -/*! - * @brief Creates a new, autoreleased open file failed exception. - * - * @param path A string with the path of the file tried to open - * @param mode A string with the mode in which the file should have been opened - * @return A new, autoreleased open file failed exception - */ -+ (instancetype)exceptionWithPath: (OFString*)path - mode: (OFString*)mode; - -/*! - * @brief Creates a new, autoreleased open file failed exception. - * - * @param path A string with the path of the file tried to open - * @param mode A string with the mode in which the file should have been opened - * @param errNo The errno of the error - * @return A new, autoreleased open file failed exception - */ -+ (instancetype)exceptionWithPath: (OFString*)path - mode: (OFString*)mode - errNo: (int)errNo; - -/*! - * @brief Initializes an already allocated open file failed exception. - * - * @param path A string with the path of the file which couldn't be opened - * @param mode A string with the mode in which the file should have been opened - * @return An initialized open file failed exception - */ -- initWithPath: (OFString*)path - mode: (OFString*)mode; - -/*! - * @brief Initializes an already allocated open file failed exception. - * - * @param path A string with the path of the file which couldn't be opened - * @param mode A string with the mode in which the file should have been opened - * @param errNo The errno of the error - * @return An initialized open file failed exception - */ -- initWithPath: (OFString*)path - mode: (OFString*)mode - errNo: (int)errNo; - -/*! - * @brief Returns a string with the path of the file which couldn't be opened. - * - * @return A string with the path of the file which couldn't be opened - */ -- (OFString*)path; - -/*! - * @brief Returns a string with the mode in which the file should have been - * opened. - * - * @return A string with the mode in which the file should have been opened - */ -- (OFString*)mode; - -/*! - * @brief Returns the errno from when the exception was created. - * - * @return The errno from when the exception was created - */ -- (int)errNo; -@end DELETED src/exceptions/OFOpenFileFailedException.m Index: src/exceptions/OFOpenFileFailedException.m ================================================================== --- src/exceptions/OFOpenFileFailedException.m +++ src/exceptions/OFOpenFileFailedException.m @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * 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. - */ - -#include "config.h" - -#import "OFOpenFileFailedException.h" -#import "OFString.h" - -@implementation OFOpenFileFailedException -+ (instancetype)exceptionWithPath: (OFString*)path - mode: (OFString*)mode -{ - return [[[self alloc] initWithPath: path - mode: mode] autorelease]; -} - -+ (instancetype)exceptionWithPath: (OFString*)path - mode: (OFString*)mode - errNo: (int)errNo -{ - return [[[self alloc] initWithPath: path - mode: mode - errNo: errNo] autorelease]; -} - -- init -{ - OF_INVALID_INIT_METHOD -} - -- initWithPath: (OFString*)path - mode: (OFString*)mode -{ - self = [super init]; - - @try { - _path = [path copy]; - _mode = [mode copy]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- initWithPath: (OFString*)path - mode: (OFString*)mode - errNo: (int)errNo -{ - self = [super init]; - - @try { - _path = [path copy]; - _mode = [mode copy]; - _errNo = errNo; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_path release]; - [_mode release]; - - [super dealloc]; -} - -- (OFString*)description -{ - if (_errNo != 0) - return [OFString stringWithFormat: - @"Failed to open file %@ with mode %@: %@", - _path, _mode, of_strerror(_errNo)]; - else - return [OFString stringWithFormat: - @"Failed to open file %@ with mode %@!", - _path, _mode]; -} - -- (OFString*)path -{ - OF_GETTER(_path, true) -} - -- (OFString*)mode -{ - OF_GETTER(_mode, true) -} - -- (int)errNo -{ - return _errNo; -} -@end ADDED src/exceptions/OFOpenItemFailedException.h Index: src/exceptions/OFOpenItemFailedException.h ================================================================== --- src/exceptions/OFOpenItemFailedException.h +++ src/exceptions/OFOpenItemFailedException.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * 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" + +/*! + * @class OFOpenItemFailedException \ + * OFOpenItemFailedException.h ObjFW/OFOpenItemFailedException.h + * + * @brief An exception indicating an item couldn't be opened. + */ +@interface OFOpenItemFailedException: OFException +{ + OFString *_path, *_mode; + int _errNo; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly, copy) OFString *path, *mode; +@property (readonly) int errNo; +#endif + +/*! + * @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: (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 + * @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 + * @return A new, autoreleased open item failed exception + */ ++ (instancetype)exceptionWithPath: (OFString*)path + mode: (OFString*)mode + errNo: (int)errNo; + +/*! + * @brief Initializes an already allocated open item failed exception. + * + * @param path A string with the path of the item which couldn't 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 couldn't 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: (OFString*)mode; + +/*! + * @brief Initializes an already allocated open item failed exception. + * + * @param path A string with the path of the item which couldn't be opened + * @param errNo The errno of the error + * @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 couldn't be opened + * @param mode A string with the mode in which the item should have been opened + * @param errNo The errno of the error + * @return An initialized open item failed exception + */ +- initWithPath: (OFString*)path + mode: (OFString*)mode + errNo: (int)errNo; + +/*! + * @brief Returns a string with the path of the item which couldn't be opened. + * + * @return A string with the path of the item which couldn't be opened + */ +- (OFString*)path; + +/*! + * @brief Returns a string with the mode in which the item should have been + * opened. + * + * @return A string with the mode in which the item should have been opened + */ +- (OFString*)mode; + +/*! + * @brief Returns the errno from when the exception was created. + * + * @return The errno from when the exception was created + */ +- (int)errNo; +@end ADDED src/exceptions/OFOpenItemFailedException.m Index: src/exceptions/OFOpenItemFailedException.m ================================================================== --- src/exceptions/OFOpenItemFailedException.m +++ src/exceptions/OFOpenItemFailedException.m @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * 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. + */ + +#include "config.h" + +#import "OFOpenItemFailedException.h" +#import "OFString.h" + +@implementation OFOpenItemFailedException ++ (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 + mode: mode + errNo: errNo] autorelease]; +} + +- init +{ + OF_INVALID_INIT_METHOD +} + +- initWithPath: (OFString*)path +{ + self = [super init]; + + @try { + _path = [path copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithPath: (OFString*)path + mode: (OFString*)mode +{ + self = [super init]; + + @try { + _path = [path copy]; + _mode = [mode copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithPath: (OFString*)path + errNo: (int)errNo +{ + self = [super init]; + + @try { + _path = [path copy]; + _errNo = errNo; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithPath: (OFString*)path + mode: (OFString*)mode + errNo: (int)errNo +{ + self = [super init]; + + @try { + _path = [path copy]; + _mode = [mode copy]; + _errNo = errNo; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_path release]; + [_mode release]; + + [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]; + } +} + +- (OFString*)path +{ + OF_GETTER(_path, true) +} + +- (OFString*)mode +{ + OF_GETTER(_mode, true) +} + +- (int)errNo +{ + return _errNo; +} +@end Index: src/runtime/exception.m ================================================================== --- src/runtime/exception.m +++ src/runtime/exception.m @@ -70,12 +70,11 @@ #define CLEANUP_FOUND 0x01 #define HANDLER_FOUND 0x02 struct _Unwind_Context; -typedef enum -{ +typedef enum { _URC_OK = 0, _URC_FATAL_PHASE1_ERROR = 3, _URC_END_OF_STACK = 5, _URC_HANDLER_FOUND = 6, _URC_INSTALL_CONTEXT = 7, Index: utils/ofhash/OFHash.m ================================================================== --- utils/ofhash/OFHash.m +++ utils/ofhash/OFHash.m @@ -26,11 +26,11 @@ #import "OFSHA256Hash.h" #import "OFSHA384Hash.h" #import "OFSHA512Hash.h" #import "OFStdIOStream.h" -#import "OFOpenFileFailedException.h" +#import "OFOpenItemFailedException.h" #import "OFReadFailedException.h" @interface OFHash: OFObject @end @@ -95,11 +95,11 @@ file = of_stdin; else { @try { file = [OFFile fileWithPath: path mode: @"rb"]; - } @catch (OFOpenFileFailedException *e) { + } @catch (OFOpenItemFailedException *e) { [of_stderr writeFormat: @"Failed to open file %@: %s\n", [e path], strerror([e errNo])]; exitStatus = 1; Index: utils/ofzip/OFZIP.m ================================================================== --- utils/ofzip/OFZIP.m +++ utils/ofzip/OFZIP.m @@ -29,11 +29,11 @@ #import "OFZIPArchive.h" #import "OFZIPArchiveEntry.h" #import "OFCreateDirectoryFailedException.h" #import "OFInvalidFormatException.h" -#import "OFOpenFileFailedException.h" +#import "OFOpenItemFailedException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" #import "autorelease.h" #import "macros.h" @@ -188,11 +188,11 @@ } @catch (OFCreateDirectoryFailedException *e) { [of_stderr writeFormat: @"\rFailed to create directory %@: %s\n", [e path], strerror([e errNo])]; _exitStatus = 1; - } @catch (OFOpenFileFailedException *e) { + } @catch (OFOpenItemFailedException *e) { [of_stderr writeFormat: @"\rFailed to open file %@: %s\n", [e path], strerror([e errNo])]; _exitStatus = 1; } @@ -210,11 +210,11 @@ { OFZIPArchive *archive = nil; @try { archive = [OFZIPArchive archiveWithPath: path]; - } @catch (OFOpenFileFailedException *e) { + } @catch (OFOpenItemFailedException *e) { [of_stderr writeFormat: @"Failed to open file %@: %s\n", [e path], strerror([e errNo])]; [OFApplication terminateWithStatus: 1]; } @catch (OFReadFailedException *e) { [of_stderr writeFormat: @"Failed to read file %@: %s\n",