@@ -185,11 +185,12 @@ { OFString *ret; char *buffer = getcwd(NULL, 0); @try { - ret = [OFString stringWithCString: buffer]; + ret = [OFString stringWithCString: buffer + encoding: OF_STRING_ENCODING_NATIVE]; } @finally { free(buffer); } return ret; @@ -197,11 +198,12 @@ + (BOOL)fileExistsAtPath: (OFString*)path { struct stat s; - if (stat([path cString], &s) == -1) + if (stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], + &s) == -1) return NO; if (S_ISREG(s.st_mode)) return YES; @@ -210,11 +212,12 @@ + (BOOL)directoryExistsAtPath: (OFString*)path { struct stat s; - if (stat([path cString], &s) == -1) + if (stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], + &s) == -1) return NO; if (S_ISDIR(s.st_mode)) return YES; @@ -222,13 +225,14 @@ } + (void)createDirectoryAtPath: (OFString*)path { #ifndef _WIN32 - if (mkdir([path cString], DIR_MODE)) + if (mkdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], + DIR_MODE)) #else - if (mkdir([path cString])) + if (mkdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #endif @throw [OFCreateDirectoryFailedException newWithClass: self path: path]; } @@ -239,11 +243,12 @@ #ifndef _WIN32 DIR *dir; struct dirent *dirent; - if ((dir = opendir([path cString])) == NULL) + if ((dir = opendir([path cStringWithEncoding: + OF_STRING_ENCODING_NATIVE])) == NULL) @throw [OFOpenFileFailedException newWithClass: self path: path mode: @"r"]; @try { @@ -254,11 +259,13 @@ if (!strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, "..")) continue; - file = [OFString stringWithCString: dirent->d_name]; + file = [OFString + stringWithCString: dirent->d_name + encoding: OF_STRING_ENCODING_NATIVE]; [files addObject: file]; [pool releaseObjects]; } @@ -308,21 +315,21 @@ return files; } + (void)changeToDirectory: (OFString*)path { - if (chdir([path cString])) + if (chdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) @throw [OFChangeDirectoryFailedException newWithClass: self path: path]; } #ifndef _PSP + (void)changeModeOfFile: (OFString*)path toMode: (mode_t)mode { # ifndef _WIN32 - if (chmod([path cString], mode)) + if (chmod([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], mode)) @throw [OFChangeFileModeFailedException newWithClass: self path: path mode: mode]; # else DWORD attributes = GetFileAttributes([path cString]); @@ -347,11 +354,12 @@ + (OFDate*)modificationDateOfFile: (OFString*)path { struct stat s; - if (stat([path cString], &s) == -1) + if (stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], + &s) == -1) /* FIXME: Maybe use another exception? */ @throw [OFOpenFileFailedException newWithClass: self path: path mode: @"r"]; @@ -377,11 +385,12 @@ @try { # endif if (owner != nil) { struct passwd *passwd; - if ((passwd = getpwnam([owner cString])) == NULL) + if ((passwd = getpwnam([owner cStringWithEncoding: + OF_STRING_ENCODING_NATIVE])) == NULL) @throw [OFChangeFileOwnerFailedException newWithClass: self path: path owner: owner group: group]; @@ -390,11 +399,12 @@ } if (group != nil) { struct group *group_; - if ((group_ = getgrnam([group cString])) == NULL) + if ((group_ = getgrnam([group cStringWithEncoding: + OF_STRING_ENCODING_NATIVE])) == NULL) @throw [OFChangeFileOwnerFailedException newWithClass: self path: path owner: owner group: group]; @@ -405,11 +415,12 @@ } @finally { [mutex unlock]; } # endif - if (chown([path cString], uid, gid)) + if (chown([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], + uid, gid)) @throw [OFChangeFileOwnerFailedException newWithClass: self path: path owner: owner group: group]; } @@ -477,13 +488,15 @@ destination = [OFString stringWithPath: destination, filename, nil]; } #ifndef _WIN32 - if (rename([source cString], [destination cString])) + if (rename([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE], + [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #else - if (!MoveFile([source cString], [destination cString])) + if (!MoveFile([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE], + [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #endif @throw [OFRenameFileFailedException newWithClass: self sourcePath: source destinationPath: destination]; @@ -491,21 +504,21 @@ } + (void)deleteFileAtPath: (OFString*)path { #ifndef _WIN32 - if (unlink([path cString])) + if (unlink([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #else - if (!DeleteFile([path cString])) + if (!DeleteFile([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #endif @throw [OFDeleteFileFailedException newWithClass: self path: path]; } + (void)deleteDirectoryAtPath: (OFString*)path { - if (rmdir([path cString])) + if (rmdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) @throw [OFDeleteDirectoryFailedException newWithClass: self path: path]; } #ifndef _WIN32 @@ -518,11 +531,12 @@ OFString *filename = [source lastPathComponent]; destination = [OFString stringWithPath: destination, filename, nil]; } - if (link([source cString], [destination cString]) != 0) + if (link([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE], + [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE]) != 0) @throw [OFLinkFailedException newWithClass: self sourcePath: source destinationPath: destination]; [pool release]; @@ -539,11 +553,12 @@ OFString *filename = [source lastPathComponent]; destination = [OFString stringWithPath: destination, filename, nil]; } - if (symlink([source cString], [destination cString]) != 0) + if (symlink([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE], + [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE]) != 0) @throw [OFSymlinkFailedException newWithClass: self sourcePath: source destinationPath: destination]; [pool release]; @@ -564,16 +579,17 @@ self = [super init]; @try { int flags; - if ((flags = parse_mode([mode cString])) == -1) + if ((flags = parse_mode([mode cStringWithEncoding: + OF_STRING_ENCODING_NATIVE])) == -1) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; - if ((fileDescriptor = open([path cString], flags, - DEFAULT_MODE)) == -1) + if ((fileDescriptor = open([path cStringWithEncoding: + OF_STRING_ENCODING_NATIVE], flags, DEFAULT_MODE)) == -1) @throw [OFOpenFileFailedException newWithClass: isa path: path mode: mode]; closable = YES;