@@ -110,11 +110,11 @@ of_stat(OFString *path, of_stat_t *buffer) { #ifdef _WIN32 return _wstat([path UTF16String], buffer); #else - return stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], + return stat([path cStringWithEncoding: [OFString nativeOSEncoding]], buffer); #endif } int @@ -121,14 +121,14 @@ of_lstat(OFString *path, of_stat_t *buffer) { #if defined(_WIN32) return _wstat([path UTF16String], buffer); #elif defined(HAVE_LSTAT) - return lstat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], + return lstat([path cStringWithEncoding: [OFString nativeOSEncoding]], buffer); #else - return stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], + return stat([path cStringWithEncoding: [OFString nativeOSEncoding]], buffer); #endif } static int @@ -204,11 +204,11 @@ #endif @try { #ifndef _WIN32 ret = [OFString stringWithCString: buffer - encoding: OF_STRING_ENCODING_NATIVE]; + encoding: [OFString nativeOSEncoding]]; #else ret = [OFString stringWithUTF16String: buffer]; #endif } @finally { free(buffer); @@ -271,11 +271,11 @@ { if (path == nil) @throw [OFInvalidArgumentException exception]; #ifndef _WIN32 - if (mkdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], + if (mkdir([path cStringWithEncoding: [OFString nativeOSEncoding]], DIR_MODE)) #else if (_wmkdir([path UTF16String])) #endif @throw [OFCreateDirectoryFailedException @@ -326,22 +326,23 @@ } + (OFArray*)contentsOfDirectoryAtPath: (OFString*)path { OFMutableArray *files; + of_string_encoding_t encoding; if (path == nil) @throw [OFInvalidArgumentException exception]; files = [OFMutableArray array]; + encoding = [OFString nativeOSEncoding]; #ifndef _WIN32 DIR *dir; struct dirent *dirent; - if ((dir = opendir([path cStringWithEncoding: - OF_STRING_ENCODING_NATIVE])) == NULL) + if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL) @throw [OFOpenFileFailedException exceptionWithPath: path mode: @"r"]; @try { while ((dirent = readdir(dir)) != NULL) { @@ -350,13 +351,12 @@ if (!strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, "..")) continue; - file = [OFString - stringWithCString: dirent->d_name - encoding: OF_STRING_ENCODING_NATIVE]; + file = [OFString stringWithCString: dirent->d_name + encoding: encoding]; [files addObject: file]; objc_autoreleasePoolPop(pool); } } @finally { @@ -404,11 +404,11 @@ { if (path == nil) @throw [OFInvalidArgumentException exception]; #ifndef _WIN32 - if (chdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) + if (chdir([path cStringWithEncoding: [OFString nativeOSEncoding]])) #else if (_wchdir([path UTF16String])) #endif @throw [OFChangeCurrentDirectoryPathFailedException exceptionWithPath: path]; @@ -452,11 +452,11 @@ { if (path == nil) @throw [OFInvalidArgumentException exception]; # ifndef _WIN32 - if (chmod([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], + if (chmod([path cStringWithEncoding: [OFString nativeOSEncoding]], permissions)) # else if (_wchmod([path UTF16String], permissions)) # endif @throw [OFChangePermissionsFailedException @@ -470,13 +470,16 @@ owner: (OFString*)owner group: (OFString*)group { uid_t uid = -1; gid_t gid = -1; + of_string_encoding_t encoding; if (path == nil || (owner == nil && group == nil)) @throw [OFInvalidArgumentException exception]; + + encoding = [OFString nativeOSEncoding]; # ifdef OF_HAVE_THREADS if (!of_mutex_lock(&mutex)) @throw [OFLockFailedException exception]; @@ -483,12 +486,12 @@ @try { # endif if (owner != nil) { struct passwd *passwd; - if ((passwd = getpwnam([owner cStringWithEncoding: - OF_STRING_ENCODING_NATIVE])) == NULL) + if ((passwd = getpwnam([owner + cStringWithEncoding: encoding])) == NULL) @throw [OFChangeOwnerFailedException exceptionWithPath: path owner: owner group: group]; @@ -496,12 +499,12 @@ } if (group != nil) { struct group *group_; - if ((group_ = getgrnam([group cStringWithEncoding: - OF_STRING_ENCODING_NATIVE])) == NULL) + if ((group_ = getgrnam([group + cStringWithEncoding: encoding])) == NULL) @throw [OFChangeOwnerFailedException exceptionWithPath: path owner: owner group: group]; @@ -512,12 +515,11 @@ if (!of_mutex_unlock(&mutex)) @throw [OFUnlockFailedException exception]; } # endif - if (chown([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], - uid, gid)) + if (chown([path cStringWithEncoding: encoding], uid, gid)) @throw [OFChangeOwnerFailedException exceptionWithPath: path owner: owner group: group]; } #endif @@ -642,10 +644,11 @@ + (void)moveItemAtPath: (OFString*)source toPath: (OFString*)destination { void *pool; of_stat_t s; + of_string_encoding_t encoding; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); @@ -655,13 +658,15 @@ @throw [OFCopyItemFailedException exceptionWithSourcePath: source destinationPath: destination]; } + encoding = [OFString nativeOSEncoding]; + #ifndef _WIN32 - if (rename([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE], - [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) { + if (rename([source cStringWithEncoding: encoding], + [destination cStringWithEncoding: encoding])) { #else if (_wrename([source UTF16String], [destination UTF16String])) { #endif if (errno != EXDEV) @throw [OFMoveItemFailedException @@ -725,11 +730,11 @@ objc_autoreleasePoolPop(pool2); } } #ifndef _WIN32 - if (remove([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) + if (remove([path cStringWithEncoding: [OFString nativeOSEncoding]])) #else if (_wremove([path UTF16String])) #endif @throw [OFRemoveItemFailedException exceptionWithPath: path]; @@ -739,18 +744,20 @@ #ifdef OF_HAVE_LINK + (void)linkItemAtPath: (OFString*)source toPath: (OFString*)destination { void *pool; + of_string_encoding_t encoding; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); + encoding = [OFString nativeOSEncoding]; - if (link([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE], - [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE]) != 0) + if (link([source cStringWithEncoding: encoding], + [destination cStringWithEncoding: encoding]) != 0) @throw [OFLinkFailedException exceptionWithSourcePath: source destinationPath: destination]; objc_autoreleasePoolPop(pool); @@ -760,18 +767,20 @@ #ifdef OF_HAVE_SYMLINK + (void)createSymbolicLinkAtPath: (OFString*)destination withDestinationPath: (OFString*)source { void *pool; + of_string_encoding_t encoding; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); + encoding = [OFString nativeOSEncoding]; - if (symlink([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE], - [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE]) != 0) + if (symlink([source cStringWithEncoding: encoding], + [destination cStringWithEncoding: encoding]) != 0) @throw [OFCreateSymbolicLinkFailedException exceptionWithSourcePath: source destinationPath: destination]; objc_autoreleasePoolPop(pool); @@ -779,23 +788,25 @@ + (OFString*)destinationOfSymbolicLinkAtPath: (OFString*)path { char destination[PATH_MAX]; ssize_t length; + of_string_encoding_t encoding; if (path == nil) @throw [OFInvalidArgumentException exception]; - length = readlink([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], + encoding = [OFString nativeOSEncoding]; + length = readlink([path cStringWithEncoding: encoding], destination, PATH_MAX); if (length < 0) @throw [OFOpenFileFailedException exceptionWithPath: path mode: @"r"]; return [OFString stringWithCString: destination - encoding: OF_STRING_ENCODING_NATIVE + encoding: encoding length: length]; } #endif - init @@ -814,11 +825,11 @@ if ((flags = parseMode([mode UTF8String])) == -1) @throw [OFInvalidArgumentException exception]; #ifndef _WIN32 if ((_fd = open([path cStringWithEncoding: - OF_STRING_ENCODING_NATIVE], flags, DEFAULT_MODE)) == -1) + [OFString nativeOSEncoding]], flags, DEFAULT_MODE)) == -1) #else if ((_fd = _wopen([path UTF16String], flags, DEFAULT_MODE)) == -1) #endif @throw [OFOpenFileFailedException