@@ -33,10 +33,11 @@ #import "OFURL.h" #import "OFURLHandler.h" #import "OFChangeCurrentDirectoryPathFailedException.h" #import "OFCopyItemFailedException.h" +#import "OFGetCurrentDirectoryPathFailedException.h" #import "OFInvalidArgumentException.h" #import "OFMoveItemFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFRemoveItemFailedException.h" @@ -157,22 +158,18 @@ } return [OFString stringWithCString: buffer encoding: [OFLocalization encoding]]; #else - OFString *ret; - char *buffer = getcwd(NULL, 0); - - @try { - ret = [OFString - stringWithCString: buffer - encoding: [OFLocalization encoding]]; - } @finally { - free(buffer); - } - - return ret; + char buffer[PATH_MAX]; + + if ((getcwd(buffer, PATH_MAX)) == NULL) + @throw [OFGetCurrentDirectoryPathFailedException + exceptionWithErrNo: errno]; + + return [OFString stringWithCString: buffer + encoding: [OFLocalization encoding]]; #endif } - (OFURL *)currentDirectoryURL {