Add path handling updates

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/branches/path-handling@21216 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2005-05-12 05:11:50 +00:00
parent c71dcdfc48
commit 1661351869
7 changed files with 133 additions and 467 deletions

View file

@ -217,10 +217,6 @@
- (BOOL) fileExistsAtPath: (NSString*)path isDirectory: (BOOL*)isDirectory;
- (NSDictionary*) fileSystemAttributesAtPath: (NSString*)path;
- (const char*) fileSystemRepresentationWithPath: (NSString*)path;
#ifndef NO_GNUSTEP
- (NSString*) localFromOpenStepPath:(NSString*)path;
- (NSString*) openStepPathFromLocal:(NSString*)localPath;
#endif
- (BOOL) isExecutableFileAtPath: (NSString*)path;
- (BOOL) isDeletableFileAtPath: (NSString*)path;
- (BOOL) isReadableFileAtPath: (NSString*)path;
@ -302,7 +298,6 @@
void *_stack; /* GSIArray */
NSString *_topPath;
NSString *_currentFilePath;
NSString *(*_openStepPathFromLocalImp)(id, SEL, id);
struct
{
BOOL isRecursive: 1;

View file

@ -351,10 +351,6 @@ enum {
caseSensitive: (BOOL)flag
matchesIntoArray: (NSArray**)outputArray
filterTypes: (NSArray*)filterTypes;
#ifndef NO_GNUSTEP
- (NSString*) localFromOpenStepPath;
- (NSString*) openStepPathFromLocal;
#endif
/**
* Converts the receiver to a C string path expressed in the character

View file

@ -1001,7 +1001,8 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
- (id) initForReadingAtPath: (NSString*)path
{
#if defined(__MINGW__)
int d = _wopen([[path localFromOpenStepPath] unicharString], O_RDONLY|O_BINARY);
int d = _wopen([path cStringUsingEncoding: NSUnicodeStringEncoding],
O_RDONLY|O_BINARY);
#else
int d = open([path fileSystemRepresentation], O_RDONLY|O_BINARY);
#endif
@ -1027,7 +1028,8 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
- (id) initForWritingAtPath: (NSString*)path
{
#if defined(__MINGW__)
int d = _wopen([[path localFromOpenStepPath] unicharString], O_WRONLY|O_BINARY);
int d = _wopen([path cStringUsingEncoding: NSUnicodeStringEncoding],
O_WRONLY|O_BINARY);
#else
int d = open([path fileSystemRepresentation], O_WRONLY|O_BINARY);
#endif
@ -1053,7 +1055,8 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
- (id) initForUpdatingAtPath: (NSString*)path
{
#if defined(__MINGW__)
int d = _wopen([[path localFromOpenStepPath] unicharString], O_RDWR|O_BINARY);
int d = _wopen([path cStringUsingEncoding: NSUnicodeStringEncoding],
O_RDWR|O_BINARY);
#else
int d = open([path fileSystemRepresentation], O_RDWR|O_BINARY);
#endif

View file

@ -132,8 +132,6 @@ static IMP appendImp;
static BOOL
readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
{
NSString *localPath = [path localFromOpenStepPath];
#if defined(__MINGW__)
const unichar *thePath = NULL;
#else
@ -149,13 +147,13 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
#endif
#if defined(__MINGW__)
thePath = [localPath unicharString];
thePath = [path cStringUnsingEncoding: NSUnicodeStringEncoding];
#else
thePath = [localPath fileSystemRepresentation];
thePath = [path fileSystemRepresentation];
#endif
if (thePath == NULL)
{
NSWarnFLog(@"Open (%@) attempt failed - bad path",localPath);
NSWarnFLog(@"Open (%@) attempt failed - bad path",path);
return NO;
}
@ -167,7 +165,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
if (theFile == NULL) /* We failed to open the file. */
{
NSWarnFLog(@"Open (%@) attempt failed - %s",localPath,
NSWarnFLog(@"Open (%@) attempt failed - %s",path,
GSLastErrorStr(errno));
goto failure;
}
@ -178,7 +176,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
c = fseek(theFile, 0L, SEEK_END);
if (c != 0)
{
NSWarnFLog(@"Seek to end of file (%@) failed - %s",localPath,
NSWarnFLog(@"Seek to end of file (%@) failed - %s",path,
GSLastErrorStr(errno));
goto failure;
}
@ -190,7 +188,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
fileLength = ftell(theFile);
if (fileLength == -1)
{
NSWarnFLog(@"Ftell on %@ failed - %s",localPath,
NSWarnFLog(@"Ftell on %@ failed - %s",path,
GSLastErrorStr(errno));
goto failure;
}
@ -202,7 +200,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
c = fseek(theFile, 0L, SEEK_SET);
if (c != 0)
{
NSWarnFLog(@"Fseek to start of file (%@) failed - %s",localPath,
NSWarnFLog(@"Fseek to start of file (%@) failed - %s",path,
GSLastErrorStr(errno));
goto failure;
}
@ -210,7 +208,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
if (fileLength == 0)
{
unsigned char buf[BUFSIZ];
/*
* Special case ... a file of length zero may be a named pipe or some
* file in the /proc filesystem, which will return us data if we read
@ -228,7 +226,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
}
if (tmp == 0)
{
NSLog(@"Malloc failed for file (%@) of length %d - %s",localPath,
NSLog(@"Malloc failed for file (%@) of length %d - %s",path,
fileLength + c, GSLastErrorStr(errno));
goto failure;
}
@ -241,15 +239,15 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
tmp = NSZoneMalloc(zone, fileLength);
if (tmp == 0)
{
NSLog(@"Malloc failed for file (%@) of length %d - %s",localPath,
NSLog(@"Malloc failed for file (%@) of length %d - %s",path,
fileLength, GSLastErrorStr(errno));
goto failure;
}
c = fread(tmp, 1, fileLength, theFile);
if (c != (int)fileLength)
{
NSWarnFLog(@"read of file (%@) contents failed - %s",localPath,
NSWarnFLog(@"read of file (%@) contents failed - %s",path,
GSLastErrorStr(errno));
goto failure;
}
@ -259,7 +257,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
*len = fileLength;
fclose(theFile);
return YES;
/*
* Just in case the failure action needs to be changed.
*/
@ -821,39 +819,39 @@ static unsigned gsu32Align;
*/
- (BOOL) writeToFile: (NSString*)path atomically: (BOOL)useAuxiliaryFile
{
NSString *localPath = [path localFromOpenStepPath];
#if defined(__MINGW__)
unichar wthePath[[localPath length]+100];
unichar wtheRealPath[[localPath length]+100];
unichar wthePath[[path length]+100];
unichar wtheRealPath[[path length]+100];
#else
char thePath[BUFSIZ*2+8];
char theRealPath[BUFSIZ*2];
char thePath[BUFSIZ*2+8];
char theRealPath[BUFSIZ*2];
#endif
int c;
FILE *theFile;
BOOL error_BadPath = YES;
int c;
FILE *theFile;
BOOL error_BadPath = YES;
#if defined(__MINGW__)
[localPath getCharacters:wtheRealPath];
wtheRealPath[[localPath length]] = L'\0';
error_BadPath = ([localPath length] <= 0);
[path getCharacters:wtheRealPath];
wtheRealPath[[path length]] = L'\0';
error_BadPath = ([path length] <= 0);
#else
if ([localPath canBeConvertedToEncoding: [NSString defaultCStringEncoding]])
if ([path canBeConvertedToEncoding: [NSString defaultCStringEncoding]])
{
const char *cPath = [path cString];
if (strlen(cPath) < (BUFSIZ*2))
{
const char *local_c_path = [localPath cString];
if (local_c_path != NULL && strlen(local_c_path) < (BUFSIZ*2))
{
strcpy(theRealPath,local_c_path);
error_BadPath = NO;
}
}
strcpy(theRealPath, cPath);
error_BadPath = NO;
}
}
#endif
if (error_BadPath)
{
NSWarnMLog(@"Open (%@) attempt failed - bad path",path);
return NO;
}
if (error_BadPath)
{
NSWarnMLog(@"Open (%@) attempt failed - bad path",path);
return NO;
}
#ifdef HAVE_MKSTEMP
if (useAuxiliaryFile)
@ -865,9 +863,9 @@ static unsigned gsu32Align;
strcat(thePath, "XXXXXX");
if ((desc = mkstemp(thePath)) < 0)
{
NSWarnMLog(@"mkstemp (%s) failed - %s", thePath,
NSWarnMLog(@"mkstemp (%s) failed - %s", thePath,
GSLastErrorStr(errno));
goto failure;
goto failure;
}
mask = umask(0);
umask(mask);
@ -903,9 +901,9 @@ static unsigned gsu32Align;
strcat(thePath, "XXXXXX");
if (mktemp(thePath) == 0)
{
NSWarnMLog(@"mktemp (%s) failed - %s", thePath,
NSWarnMLog(@"mktemp (%s) failed - %s", thePath,
GSLastErrorStr(errno));
goto failure;
goto failure;
}
#endif
}
@ -918,7 +916,7 @@ static unsigned gsu32Align;
#endif
}
/* Open the file (whether temp or real) for writing. */
/* Open the file (whether temp or real) for writing. */
#if defined(__MINGW__)
theFile = _wfopen(wthePath, L"wb");
#else
@ -926,8 +924,9 @@ static unsigned gsu32Align;
#endif
#endif
if (theFile == NULL) /* Something went wrong; we weren't
* even able to open the file. */
/* Something went wrong; we weren't
* even able to open the file. */
if (theFile == NULL)
{
#if defined(__MINGW__)
NSWarnMLog(@"Open (%@) failed - %s",
@ -940,12 +939,12 @@ static unsigned gsu32Align;
}
/* Now we try and write the NSData's bytes to the file. Here `c' is
* the number of bytes which were successfully written to the file
* in the fwrite() call. */
* the number of bytes which were successfully written to the file
* in the fwrite() call. */
c = fwrite([self bytes], sizeof(char), [self length], theFile);
if (c < (int)[self length]) /* We failed to write everything for
* some reason. */
/* We failed to write everything for * some reason. */
if (c < (int)[self length])
{
#if defined(__MINGW__)
NSWarnMLog(@"Fwrite (%@) failed - %s",
@ -961,8 +960,8 @@ static unsigned gsu32Align;
c = fclose(theFile);
if (c != 0) /* I can't imagine what went wrong
* closing the file, but we got here,
* so we need to deal with it. */
* closing the file, but we got here,
* so we need to deal with it. */
{
#if defined(__MINGW__)
NSWarnMLog(@"Fclose (%@) failed - %s",
@ -1019,18 +1018,18 @@ static unsigned gsu32Align;
c = rename(thePath, theRealPath);
#endif
if (c != 0) /* Many things could go wrong, I guess. */
{
{
#if defined(__MINGW__)
NSWarnMLog(@"Rename ('%@' to '%@') failed - %s",
NSWarnMLog(@"Rename ('%@' to '%@') failed - %s",
[NSString stringWithCharacters:wthePath length:wcslen(wthePath)],
[NSString stringWithCharacters:wtheRealPath length:wcslen(wtheRealPath)],
GSLastErrorStr(errno));
#else
NSWarnMLog(@"Rename ('%s' to '%s') failed - %s",
NSWarnMLog(@"Rename ('%s' to '%s') failed - %s",
thePath, theRealPath, GSLastErrorStr(errno));
#endif
goto failure;
}
goto failure;
}
if (att != nil)
{
@ -1068,7 +1067,7 @@ static unsigned gsu32Align;
return YES;
/* Just in case the failure action needs to be changed. */
failure:
failure:
/*
* Attempt to tidy up by removing temporary file on failure.
*/
@ -2855,65 +2854,62 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
*/
- (id) initWithContentsOfMappedFile: (NSString*)path
{
int fd;
NSString *localPath = [path localFromOpenStepPath];
int fd;
#if defined(__MINGW__)
const unichar *thePath = [localPath unicharString];
const unichar *thePath
= [path cStringUnsingEncoding: NSUnicodeStringEncoding];
#else
const char *thePath;
thePath = [localPath fileSystemRepresentation];
const char *thePath;
thePath = [path fileSystemRepresentation];
#endif
if (thePath == NULL)
{
NSWarnMLog(@"Open (%@) attempt failed - bad path",localPath);
RELEASE(self);
return nil;
}
if (thePath == NULL)
{
NSWarnMLog(@"Open (%@) attempt failed - bad path", path);
RELEASE(self);
return nil;
}
#if defined(__MINGW__)
fd = _wopen(thePath, _O_RDONLY);
fd = _wopen(thePath, _O_RDONLY);
#else
fd = open(thePath, O_RDONLY);
fd = open(thePath, O_RDONLY);
#endif
if (fd < 0)
{
NSWarnMLog(@"unable to open %@ - %s",localPath,GSLastErrorStr(errno));
RELEASE(self);
return nil;
}
/* Find size of file to be mapped. */
length = lseek(fd, 0, SEEK_END);
if (length < 0)
{
NSWarnMLog(@"unable to seek to eof %@ - %s",localPath,
GSLastErrorStr(errno));
close(fd);
RELEASE(self);
return nil;
}
/* Position at start of file. */
if (lseek(fd, 0, SEEK_SET) != 0)
{
NSWarnMLog(@"unable to seek to sof %@ - %s", localPath,
GSLastErrorStr(errno));
close(fd);
RELEASE(self);
return nil;
}
bytes = mmap(0, length, PROT_READ, MAP_SHARED, fd, 0);
if (bytes == MAP_FAILED)
{
NSWarnMLog(@"mapping failed for %s - %s",localPath, GSLastErrorStr(errno));
close(fd);
RELEASE(self);
self = [dataMalloc allocWithZone: NSDefaultMallocZone()];
self = [self initWithContentsOfFile: path];
}
close(fd);
return self;
if (fd < 0)
{
NSWarnMLog(@"unable to open %@ - %s", path, GSLastErrorStr(errno));
RELEASE(self);
return nil;
}
/* Find size of file to be mapped. */
length = lseek(fd, 0, SEEK_END);
if (length < 0)
{
NSWarnMLog(@"unable to seek to eof %@ - %s", path, GSLastErrorStr(errno));
close(fd);
RELEASE(self);
return nil;
}
/* Position at start of file. */
if (lseek(fd, 0, SEEK_SET) != 0)
{
NSWarnMLog(@"unable to seek to sof %@ - %s", path, GSLastErrorStr(errno));
close(fd);
RELEASE(self);
return nil;
}
bytes = mmap(0, length, PROT_READ, MAP_SHARED, fd, 0);
if (bytes == MAP_FAILED)
{
NSWarnMLog(@"mapping failed for %s - %s",path, GSLastErrorStr(errno));
close(fd);
RELEASE(self);
self = [dataMalloc allocWithZone: NSDefaultMallocZone()];
self = [self initWithContentsOfFile: path];
}
close(fd);
return self;
}
@end

View file

@ -195,7 +195,7 @@
#define _NUL L'\0'
#define OS2LOCAL(M,P) [[M localFromOpenStepPath: P] unicharString]
#define OS2LOCAL(M,P) [P cStringUsingEncoding: NSUnicodeStringEncoding]
#else
@ -884,7 +884,7 @@ static NSFileManager* defaultManager = nil;
path = [NSString stringWithCString: lpath length: len];
#endif
currentDir = [self openStepPathFromLocal: path];
currentDir = path;
}
free(lpath);
}
@ -1858,176 +1858,25 @@ static NSFileManager* defaultManager = nil;
}
/**
* Convert from OpenStep internal path format (Unix-style) to a string in
* the local filesystem format, suitable for passing to system functions.<br />
* Under Unix, this simply standardizes the path and converts to a
* C string.<br />
* Under Windoze, this attempts to use local conventions to convert to a
* windows path. In GNUstep, the conventional unix syntax '~user/...' can
* be used to indicate a windoze drive specification by using the drive
* letter in place of the username, and the syntax '~@server/...' can be used
* to indicate a file located on the named windoze network server (the
* '~@' maps to the leading '//' in a windoze UNC path specification.
* Convert a path from the internal NSString format to a format suitable
* for passing to system functions.<br />
* This generally involves conversion to the character encoding used by
* the filesystem.
*/
- (const char*) fileSystemRepresentationWithPath: (NSString*)path
{
NSString *localPath;
const char *local_c_path = 0;
localPath = [self localFromOpenStepPath: path];
if (localPath
&& [localPath canBeConvertedToEncoding: [NSString defaultCStringEncoding]])
{
local_c_path = [localPath cString];
}
// FIXME ... what if the filesystem encoding is not the same as the
// default C-string encoding?
local_c_path = [path cString];
return (local_c_path);
}
/**
* Convert from OpenStep internal path format (Unix-style) to a NSString in
* the local filesystem format.
* Under Windoze, this attempts to use local conventions to convert to a
* windows path. In GNUstep, the conventional unix syntax '~user/...' can
* be used to indicate a windoze drive specification by using the drive
* letter in place of the username, and the syntax '~@server/...' can be used
* to indicate a file located on the named windoze network server (the
* '~@' maps to the leading '//' in a windoze UNC path specification.
*/
- (NSString*) localFromOpenStepPath: (NSString*)path
{
NSString *newpath = nil;
#ifdef __MINGW__
/*
* If path is in Unix format, transmogrify it so Windows functions
* can handle it
*/
int wcount; // count unichars
unichar *wc_path = 0;
int l;
path = [path stringByStandardizingPath];
wcount = [path length];
if (wcount != 0)
{
l = wcount;
wc_path = (unichar*)calloc(wcount+10,sizeof(unichar));
[path getCharacters: (unichar *)wc_path];
if (l >= 2 && wc_path[0] == L'~' && wc_path[1] == L'@')
{
// Convert to windows UNC path.
wc_path[0] = L'/';
wc_path[1] = L'/';
newpath = [NSString stringWithCharacters: wc_path length: wcount];
}
else if (l >= 2 && wc_path[0] == L'~' && iswalpha(wc_path[1])
&& (l == 2 || wc_path[2] == L'/'))
{
wc_path[0] = wc_path[1];
wc_path[1] = L':';
newpath = [NSString stringWithCharacters: wc_path length: wcount];
}
else if (l >= 3 && wc_path[0] == L'/' && wc_path[1] == L'/'
&& iswalpha(wc_path[2]))
{
if (l == 3 || wc_path[3] == L'/')
{
/* Cygwin "//c/" type absolute path */
wc_path[1] = wc_path[2];
wc_path[2] = L':';
newpath = [NSString stringWithCharacters: &wc_path[1]
length: wcount-1];
}
else
{
/* Windows absolute UNC path "//name/" */
newpath = path;
}
}
else if (isalpha(wc_path[0]) && wc_path[1] == L':')
{
/* Windows absolute path */
newpath = path;
}
else if (wc_path[0] == L'/')
{
#ifdef __CYGWIN__
if (l > 11 && wcsncmp(wc_path, L"/cygdrive/", 10) == 0
&& wc_path[11] == L'/')
{
wc_path[9] = wc_path[10];
wc_path[10] = L':';
newpath = [NSString stringWithCharacters: &wc_path[9]
length: wcount-9];
}
else
{
NSDictionary *env;
NSString *cyghome;
env = [[NSProcessInfo processInfo] environment];
cyghome = [env objectForKey: @"CYGWIN_HOME"];
if (cyghome != nil)
{
/* FIXME: Find cygwin drive? */
newpath = cyghome;
newpath = [newpath stringByAppendingPathComponent: path];
}
else
{
newpath = path;
}
}
#else
if (l >= 2 && wc_path[0] == L'/' && iswalpha(wc_path[1])
&& (l == 2 || wc_path[2] == L'/'))
{
/* Mingw /drive/... format */
wc_path[2] = L':';
newpath = [NSString stringWithCharacters: &wc_path[1]
length: wcount-1];
}
else
{
newpath = path;
}
#endif
}
else
{
newpath = path;
}
newpath = [newpath stringByReplacingString: @"/" withString: @"\\"];
if (wc_path)
{
free (wc_path);
}
}
else
{
newpath = path;
}
#else
/*
* NB ... Don't standardize path, since that would automatically
* follow symbolic links ... and mess up any code wishing to
* examine the link itsself.
* We just need the path in a form where it can be interpreted by
* operating system calls (no '~' abbreviations for user directories).
*/
newpath = [path stringByExpandingTildeInPath];
#endif
return (newpath);
}
/**
* This method converts from a local system specific filename representation
* to the internal OpenStep representation (unix-style). This should be used
* whenever a filename is read in from the local system.<br />
* In GNUstep, windoze drive specifiers are encoded in the internal path
* using the conventuional unix syntax of '~user/...' where the drive letter
* is used instead of a username.
* to an NSString object. This should be used whenever a filename is
* read in using native system calls.
*/
- (NSString*) stringWithFileSystemRepresentation: (const char*)string
length: (unsigned int)len
@ -2036,133 +1885,12 @@ static NSFileManager* defaultManager = nil;
if (string != 0)
{
// FIXME ... what if the filesystem encoding is not the same as the
// default C-string encoding?
localPath = [NSString stringWithCString: string length: len];
}
return([self openStepPathFromLocal: localPath]);
}
/**
* This method converts from a local system specific filename representation
* to the internal OpenStep representation (unix-style). This should be used
* whenever a filename is read in from the local system.<br />
* In GNUstep, windoze drive specifiers are encoded in the internal path
* using the conventuional unix syntax of '~user/...' where the drive letter
* is used instead of a username.
*/
- (NSString*) openStepPathFromLocal: (NSString*)localPath
{
#ifdef __MINGW__
int len; // count unichars
unichar *wc_path = 0;
len = [localPath length];
if (len != 0)
{
wc_path = (unichar*)calloc(len+10,sizeof(unichar));
[localPath getCharacters: (unichar *)wc_path];
}
if (wc_path)
{
const unichar *ptr = wc_path;
unichar buf[len + 20];
unsigned i;
unsigned j;
/*
* If path is in Windows format, transmogrify it so Unix functions
* can handle it
*/
if (len == 0)
{
free(wc_path);
return @"";
}
if (len >= 2 && ((ptr[1] == L'/' && ptr[0] == L'/')
|| (ptr[1] == L'\\' && ptr[0] == L'\\')))
{
/*
* Convert '//<servername>/' to '~@<servername>/' sequences.
*/
buf[0] = L'~';
buf[1] = L'@';
i = 2;
}
else if (len >= 2 && ptr[1] == L':' && iswalpha(ptr[0]))
{
/*
* Convert '<driveletter>:' to '~<driveletter>/' sequences.
*/
buf[0] = L'~';
buf[1] = ptr[0];
buf[2] = L'/';
ptr -= 1;
len++;
i = 3;
}
#ifdef __CYGWIN__
else if (len > 9 && wcsncmp(ptr, L"/cygdrive/", 10) == 0)
{
buf[0] = L'~';
ptr += 9;
len -= 9;
i = 1;
}
#else
else if (len >= 2 && ptr[0] == L'/' && iswalpha(ptr[1])
&& (len == 2 || ptr[2] == L'/'))
{
/*
* Convert '/<driveletter>' to '~<driveletter>' sequences.
*/
buf[0] = L'~';
i = 1;
}
#endif
else
{
i = 0;
}
/*
* Convert backslashes to slashes, colaescing adjacent slashes.
* Also elide '/./' sequences, because we can do so efficiently.
*/
j = i;
while (i < len)
{
if (ptr[i] == L'\\')
{
if (j == 0 || buf[j-1] != L'/')
{
if (j > 2 && buf[j-2] == L'/' && buf[j-1] == L'.')
{
j--;
}
else
{
buf[j++] = L'/';
}
}
}
else
{
buf[j++] = ptr[i];
}
i++;
}
buf[j] = _NUL;
// NSLog(@"Map '%s' to '%s'", string, buf);
free(wc_path);
return [NSString stringWithCharacters: buf length: j];
}
else
{
return(@"");
}
#endif
return localPath;
return(localPath);
}
@end /* NSFileManager */
@ -2198,8 +1926,6 @@ inline void gsedRelease(GSEnumeratedDirectory X)
#include "GNUstepBase/GSIArray.h"
static SEL ospfl = 0;
/**
* <p>This is a subclass of <code>NSEnumerator</code> which provides a full
* listing of all the files beneath a directory and its subdirectories.
@ -2223,7 +1949,6 @@ static SEL ospfl = 0;
{
/* Initialize the default manager which we access directly */
[NSFileManager defaultManager];
ospfl = @selector(openStepPathFromLocal:);
}
}
@ -2249,9 +1974,6 @@ static SEL ospfl = 0;
self = [super init];
_openStepPathFromLocalImp = (NSString *(*)(id, SEL,id))
[defaultManager methodForSelector: ospfl];
_stack = NSZoneMalloc([self zone], sizeof(GSIArray_t));
GSIArrayInitWithZoneAndCapacity(_stack, [self zone], 64);
@ -2368,9 +2090,8 @@ static SEL ospfl = 0;
continue;
}
/* Name of file to return */
returnFileName = _openStepPathFromLocalImp(defaultManager, ospfl,
[NSString stringWithCharacters: dirbuf->d_name
length: wcslen(dirbuf->d_name)]);
returnFileName = [NSString stringWithCharacters: dirbuf->d_name
length: wcslen(dirbuf->d_name)];
#else
/* Skip "." and ".." directory entries */
if (strcmp(dirbuf->d_name, ".") == 0
@ -2379,8 +2100,7 @@ static SEL ospfl = 0;
continue;
}
/* Name of file to return */
returnFileName = _openStepPathFromLocalImp(defaultManager, ospfl,
[NSString stringWithCString: dirbuf->d_name]);
returnFileName = [NSString stringWithCString: dirbuf->d_name];
#endif
returnFileName = [dir.path stringByAppendingPathComponent:
returnFileName];

View file

@ -2785,23 +2785,10 @@ handle_printf_atsign (FILE *stream,
// Getting C Strings
/**
* Returns a pointer to a null terminated string of 16-bit unichar
* The memory pointed to is not owned by the caller, so the
* caller must copy its contents to keep it.
*/
- (const unichar*) unicharString
{
NSMutableData *data;
unichar *uniStr;
data = [NSMutableData dataWithLength: ([self length] + 1) * sizeof(unichar)];
uniStr = (unichar*)[data mutableBytes];
if (uniStr != 0)
{
[self getCharacters: uniStr];
}
return uniStr;
GSOnceMLog(@"Obsolete .. use cStringUsingEncoding:");
return [self cStringUsingEncoding: NSUnicodeStringEncoding];
}
/**
@ -2830,7 +2817,7 @@ handle_printf_atsign (FILE *stream,
}
/**
* Returns a pointer to a null terminated string of 8-bit characters in the
* Returns a pointer to a null terminated string of characters in the
* specified encoding.<br />
* The memory pointed to is not owned by the caller, so the
* caller must copy its contents to keep it.<br />
@ -3456,36 +3443,6 @@ static NSFileManager *fm = nil;
return [fm fileSystemRepresentationWithPath: self];
}
/**
* Converts this string, which is assumed to be a path in Unix notation ('/'
* is file separator, '.' is extension separator) to a string path expressed
* in the convention for the host operating system.
*/
- (NSString*) localFromOpenStepPath
{
if (fm == nil)
{
fm = RETAIN([NSFileManager defaultManager]);
}
return [fm localFromOpenStepPath: self];
}
/**
* Converts this string, which is assumed to be a path in the convention
* for the host operating system to a string path expressed
* in Unix notation ('/' is file separator, '.' is extension separator).
*/
- (NSString*) openStepPathFromLocal
{
if (fm == nil)
{
fm = RETAIN([NSFileManager defaultManager]);
}
return [fm openStepPathFromLocal: self];
}
- (BOOL) getFileSystemRepresentation: (char*)buffer
maxLength: (unsigned int)size
{

View file

@ -1082,8 +1082,7 @@ quotedFromString(NSString *aString)
}
lpath = [self _fullLaunchPath];
lpath = [lpath localFromOpenStepPath];
wexecutable = [lpath unicharString];
wexecutable = [lpath cStringUsingEncoding: NSUnicodeStringEncoding];
args = [[NSMutableString alloc] initWithString: quotedFromString(lpath)];
arg_enum = [[self arguments] objectEnumerator];
@ -1154,7 +1153,7 @@ quotedFromString(NSString *aString)
1, /* inherit handles */
CREATE_UNICODE_ENVIRONMENT, /* creation flags */
envp, /* env block */
[[[self currentDirectoryPath] localFromOpenStepPath] unicharString],
[[self currentDirectoryPath] cStringUsingEncoding: NSUnicodeStringEncoding],
&start_info,
&procInfo);
NSZoneFree(NSDefaultMallocZone(), w_args);