Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -12,32 +12,14 @@ * 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. */ -#ifndef __STDC_LIMIT_MACROS -# define __STDC_LIMIT_MACROS -#endif -#ifndef __STDC_CONSTANT_MACROS -# define __STDC_CONSTANT_MACROS -#endif - -#include -#include - #import "OFSeekableStream.h" OF_ASSUME_NONNULL_BEGIN -#if defined(OF_WINDOWS) -typedef struct __stat64 of_stat_t; -#elif defined(OF_HAVE_OFF64_T) -typedef struct stat64 of_stat_t; -#else -typedef struct stat of_stat_t; -#endif - #if defined(OF_MORPHOS) && !defined(OF_IXEMUL) typedef long BPTR; #endif /*! @@ -147,15 +129,6 @@ */ - initWithHandle: (BPTR)handle; #endif @end -#ifdef __cplusplus -extern "C" { -#endif -extern int of_stat(OFString *path, of_stat_t *buffer); -extern int of_lstat(OFString *path, of_stat_t *buffer); -#ifdef __cplusplus -} -#endif - OF_ASSUME_NONNULL_END Index: src/OFFileManager.h ================================================================== --- src/OFFileManager.h +++ src/OFFileManager.h @@ -13,11 +13,11 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" -#import "OFFile.h" +#import "OFSeekableStream.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDate; Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -20,10 +20,14 @@ #ifdef HAVE_DIRENT_H # include #endif #include "unistd_wrapper.h" + +#ifdef HAVE_SYS_STAT_H +# include +#endif #ifdef HAVE_PWD_H # include #endif #ifdef HAVE_GRP_H @@ -80,10 +84,18 @@ # define S_IWOTH 0 #endif #define DEFAULT_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH #define DIR_MODE DEFAULT_MODE | S_IXUSR | S_IXGRP | S_IXOTH + +#if defined(OF_WINDOWS) +typedef struct __stat64 of_stat_t; +#elif defined(OF_HAVE_OFF64_T) +typedef struct stat64 of_stat_t; +#else +typedef struct stat of_stat_t; +#endif static OFFileManager *defaultManager; #if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS) static OFMutex *passwdMutex; @@ -94,11 +106,11 @@ #ifdef OF_WINDOWS static WINAPI BOOLEAN (*func_CreateSymbolicLinkW)(LPCWSTR, LPCWSTR, DWORD); #endif -int +static int of_stat(OFString *path, of_stat_t *buffer) { #if defined(OF_WINDOWS) return _wstat64([path UTF16String], buffer); #elif defined(OF_HAVE_OFF64_T) @@ -108,11 +120,11 @@ return stat([path cStringWithEncoding: [OFLocalization encoding]], buffer); #endif } -int +static int of_lstat(OFString *path, of_stat_t *buffer) { #if defined(OF_WINDOWS) return _wstat64([path UTF16String], buffer); #elif defined(HAVE_LSTAT) Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -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 Index: utils/ofzip/OFZIP.h ================================================================== --- utils/ofzip/OFZIP.h +++ utils/ofzip/OFZIP.h @@ -12,11 +12,13 @@ * 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 +#ifdef HAVE_SYS_STAT_H +# include +#endif #import "OFObject.h" #import "OFString.h" #import "Archive.h"