@@ -26,23 +26,20 @@ #endif #ifdef HAVE_XLOCALE_H # include #endif -#ifdef HAVE_SYS_STAT_H -# include -#endif - #import "OFString.h" #import "OFString_UTF8.h" #import "OFString_UTF8+Private.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFDataArray.h" #import "OFLocalization.h" #ifdef OF_HAVE_FILES # import "OFFile.h" +# import "OFFileManager.h" #endif #import "OFURL.h" #ifdef OF_HAVE_SOCKETS # import "OFHTTPClient.h" # import "OFHTTPRequest.h" @@ -59,10 +56,11 @@ #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" +#import "OFStatItemFailedException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "of_asprintf.h" #import "unicode.h" @@ -923,36 +921,37 @@ - initWithContentsOfFile: (OFString *)path encoding: (of_string_encoding_t)encoding { char *tmp; - of_stat_t st; + of_offset_t fileSize; @try { OFFile *file; - /* Make sure the file system is initialized */ - [OFFile class]; - - if (of_stat(path, &st) != 0) + @try { + fileSize = [[OFFileManager defaultManager] + sizeOfFileAtPath: path]; + } @catch (OFStatItemFailedException *e) { @throw [OFOpenItemFailedException exceptionWithPath: path mode: @"rb" errNo: errno]; + } if (sizeof(of_offset_t) > sizeof(size_t) && - st.st_size > (of_offset_t)SIZE_MAX) + fileSize > (of_offset_t)SIZE_MAX) @throw [OFOutOfRangeException exception]; file = [[OFFile alloc] initWithPath: path mode: @"rb"]; @try { - tmp = [self allocMemoryWithSize: (size_t)st.st_size]; + tmp = [self allocMemoryWithSize: (size_t)fileSize]; [file readIntoBuffer: tmp - exactLength: (size_t)st.st_size]; + exactLength: (size_t)fileSize]; } @finally { [file release]; } } @catch (id e) { [self release]; @@ -959,11 +958,11 @@ @throw e; } self = [self initWithCString: tmp encoding: encoding - length: (size_t)st.st_size]; + length: (size_t)fileSize]; [self freeMemory: tmp]; return self; } #endif