win32 path handling simplifications (and some bug fixes).

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21276 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2005-06-04 07:22:51 +00:00
parent 852816f419
commit d1d17bc387
11 changed files with 252 additions and 255 deletions

View file

@ -1,3 +1,19 @@
2005-06-04 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/Foundation/NSFileManager.h: hide private method in enumerator,
swap one ivar for a new one keeping size the same.
* Headers/Foundation/NSString.h: Mark some deprecated methods.
* Source/GSFileHandle.m: Merge in win32 simplifications
* Source/NSBundle.m: ditto
* Source/NSData.m: ditto
* Source/NSFileManager.m: ditto
* Source/NSPathUtilities.m: ditto
* Source/NSProcessInfo.m: ditto
* Source/NSString.m: ditto
* Source/NSTask.m: ditto
Merge in simplifications from the win32 path handling branch
and all changes/fixes since.
2005-06-04 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSFileHandle.m:

View file

@ -299,10 +299,11 @@
@interface NSDirectoryEnumerator : NSEnumerator
{
@private
void *_stack; /* GSIArray */
NSString *_topPath;
NSString *_currentFilePath;
NSString *(*_openStepPathFromLocalImp)(id, SEL, id);
NSFileManager *_mgr;
struct
{
BOOL isRecursive: 1;
@ -310,12 +311,6 @@
BOOL justContents: 1;
} _flags;
}
- (id) initWithDirectoryPath: (NSString*)path
recurseIntoSubdirectories: (BOOL)recurse
followSymlinks: (BOOL)follow
justContents: (BOOL)justContents;
- (NSDictionary*) directoryAttributes;
- (NSDictionary*) fileAttributes;
- (void) skipDescendents;

View file

@ -295,9 +295,6 @@ enum {
- (NSString*) lowercaseString;
- (NSString*) uppercaseString;
#ifndef NO_GNUSTEP
- (const unichar*) unicharString;
#endif
// Getting C Strings
- (const char*) cString;
#ifndef STRICT_OPENSTEP
@ -351,10 +348,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

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

View file

@ -581,13 +581,8 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
#endif
if (_executable_path == nil || [_executable_path length] == 0)
{
const char *tmp;
_executable_path =
[[[NSProcessInfo processInfo] arguments] objectAtIndex: 0];
tmp = [_executable_path UTF8String];
_executable_path = [[NSFileManager defaultManager]
stringWithFileSystemRepresentation: tmp length: strlen(tmp)];
_executable_path =
[self _absolutePathOfExecutable: _executable_path];
NSAssert(_executable_path, NSInternalInconsistencyException);

View file

@ -132,12 +132,10 @@ 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;
const unichar *thePath = 0;
#else
const char *thePath = NULL;
const char *thePath = 0;
#endif
FILE *theFile = 0;
void *tmp = 0;
@ -149,13 +147,13 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
#endif
#if defined(__MINGW__)
thePath = [localPath unicharString];
thePath = (const unichar*)[path fileSystemRepresentation];
#else
thePath = [localPath fileSystemRepresentation];
thePath = [path fileSystemRepresentation];
#endif
if (thePath == NULL)
if (thePath == 0)
{
NSWarnFLog(@"Open (%@) attempt failed - bad path",localPath);
NSWarnFLog(@"Open (%@) attempt failed - bad path", path);
return NO;
}
@ -165,9 +163,9 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
theFile = fopen(thePath, "rb");
#endif
if (theFile == NULL) /* We failed to open the file. */
if (theFile == 0) /* 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;
}
@ -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,7 +239,7 @@ 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;
}
@ -249,7 +247,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
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;
}
@ -657,7 +655,7 @@ static unsigned gsu32Align;
- (const void*) bytes
{
[self subclassResponsibility: _cmd];
return NULL;
return 0;
}
/**
@ -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];
unsigned int length = [path length];
unichar wthePath[length + 100];
unichar wtheRealPath[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[length] = L'\0';
error_BadPath = (length <= 0);
#else
if ([localPath canBeConvertedToEncoding: [NSString defaultCStringEncoding]])
if ([path canBeConvertedToEncoding: [NSString defaultCStringEncoding]])
{
const char *local_c_path = [path cString];
if (local_c_path != 0 && strlen(local_c_path) < (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,local_c_path);
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)
@ -926,12 +924,13 @@ static unsigned gsu32Align;
#endif
#endif
if (theFile == NULL) /* Something went wrong; we weren't
* even able to open the file. */
if (theFile == 0)
{
/* Something went wrong; we weren't
* even able to open the file. */
#if defined(__MINGW__)
NSWarnMLog(@"Open (%@) failed - %s",
[NSString stringWithCharacters:wthePath length:wcslen(wthePath)],
[NSString stringWithCharacters: wthePath length: wcslen(wthePath)],
GSLastErrorStr(errno));
#else
NSWarnMLog(@"Open (%s) failed - %s", thePath, GSLastErrorStr(errno));
@ -1152,7 +1151,7 @@ failure:
length = GSSwapBigI32ToHost(length);
if (length == -1)
{
*(const char**)data = NULL;
*(const char**)data = 0;
return;
}
else
@ -1854,7 +1853,7 @@ failure:
- (void*) mutableBytes
{
[self subclassResponsibility: _cmd];
return NULL;
return 0;
}
// Appending Data
@ -2475,7 +2474,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
len = GSSwapBigI32ToHost(len);
if (len == -1)
{
*(const char**)data = NULL;
*(const char**)data = 0;
return;
}
else
@ -2855,65 +2854,60 @@ 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 = (const unichar*)[path filesystemRepresentation];
#else
const char *thePath;
thePath = [localPath fileSystemRepresentation];
const char *thePath = [path fileSystemRepresentation];
#endif
if (thePath == NULL)
{
NSWarnMLog(@"Open (%@) attempt failed - bad path",localPath);
RELEASE(self);
return nil;
}
if (thePath == 0)
{
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

@ -171,8 +171,13 @@
#include "Foundation/NSPathUtilities.h"
#include "Foundation/NSFileManager.h"
@interface NSDirectoryEnumerator (Local)
- (id) initWithDirectoryPath: (NSString*)path
recurseIntoSubdirectories: (BOOL)recurse
followSymlinks: (BOOL)follow
justContents: (BOOL)justContents
for: (NSFileManager*)mgr;
@end
/*
* Macros to handle unichar filesystem support.
@ -197,7 +202,7 @@
#define _NUL L'\0'
#define OS2LOCAL(M,P) [[M localFromOpenStepPath: P] unicharString]
#define OS2LOCAL(M,P) (const _CHAR*)[M fileSystemRepresentationWithPath: P]
#else
@ -880,13 +885,15 @@ static NSFileManager* defaultManager = nil;
{
NSString *path;
// Windows may count the trailing nul ... we don't want to.
if (len > 0 && lpath[len] == 0) len--;
#ifdef UNICODE
path = [NSString stringWithCharacters: lpath length: len];
#else
path = [NSString stringWithCString: lpath length: len];
#endif
currentDir = [self openStepPathFromLocal: path];
currentDir = path;
}
free(lpath);
}
@ -1215,6 +1222,7 @@ static NSFileManager* defaultManager = nil;
DWORD res;
res = GetFileAttributes(lpath);
if (res == WIN32ERR)
{
return NO;
@ -1324,6 +1332,7 @@ static NSFileManager* defaultManager = nil;
DWORD res;
res = GetFileAttributes(lpath);
if (res == WIN32ERR)
{
return NO;
@ -1374,7 +1383,9 @@ static NSFileManager* defaultManager = nil;
#if defined(__MINGW__)
{
DWORD res = GetFileAttributes(lpath);
DWORD res;
res = GetFileAttributes(lpath);
if (res == WIN32ERR)
{
@ -1408,7 +1419,9 @@ static NSFileManager* defaultManager = nil;
#if defined(__MINGW__)
{
DWORD res= GetFileAttributes(lpath);
DWORD res;
res = GetFileAttributes(lpath);
if (res == WIN32ERR)
{
@ -1447,7 +1460,9 @@ static NSFileManager* defaultManager = nil;
#if defined(__MINGW__)
{
DWORD res= GetFileAttributes(lpath);
DWORD res;
res = GetFileAttributes(lpath);
if (res == WIN32ERR)
{
@ -1490,9 +1505,11 @@ static NSFileManager* defaultManager = nil;
}
#if defined(__MINGW__)
{
// TODO - handle directories
DWORD res= GetFileAttributes(lpath);
{
DWORD res;
res = GetFileAttributes(lpath);
if (res == WIN32ERR)
{
@ -1594,10 +1611,9 @@ static NSFileManager* defaultManager = nil;
*/
- (NSDictionary*) fileAttributesAtPath: (NSString*)path traverseLink: (BOOL)flag
{
const _CHAR *lpath = OS2LOCAL(self, path);
NSDictionary *d;
d = [GSAttrDictionary attributesAt: lpath traverseLink: flag];
d = [GSAttrDictionary attributesAt: OS2LOCAL(self, path) traverseLink: flag];
return d;
}
@ -1736,9 +1752,10 @@ static NSFileManager* defaultManager = nil;
the contents non-recursively once, and exit. NSDirectoryEnumerator
can perform some optms using this assumption. */
direnum = [[NSDirectoryEnumerator alloc] initWithDirectoryPath: path
recurseIntoSubdirectories: NO
followSymlinks: NO
justContents: YES];
recurseIntoSubdirectories: NO
followSymlinks: NO
justContents: YES
for: self];
content = [NSMutableArray arrayWithCapacity: 128];
nxtImp = [direnum methodForSelector: @selector(nextObject)];
@ -1778,7 +1795,8 @@ static NSFileManager* defaultManager = nil;
initWithDirectoryPath: path
recurseIntoSubdirectories: YES
followSymlinks: NO
justContents: NO]);
justContents: NO
for: self]);
}
/**
@ -1800,9 +1818,10 @@ static NSFileManager* defaultManager = nil;
return nil;
}
direnum = [[NSDirectoryEnumerator alloc] initWithDirectoryPath: path
recurseIntoSubdirectories: YES
followSymlinks: NO
justContents: NO];
recurseIntoSubdirectories: YES
followSymlinks: NO
justContents: NO
for: self];
content = [NSMutableArray arrayWithCapacity: 128];
nxtImp = [direnum methodForSelector: @selector(nextObject)];
@ -1860,53 +1879,47 @@ static NSFileManager* defaultManager = nil;
}
/**
* Convert from OpenStep internal path format (Unix-style) to a string in
* Convert from OpenStep internal string format 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.
* This representation could theoretically vary between filesystems.<br />
* On windows, the filesystem representation is utf-16 and is expected to
* be used in conjunction with the variants of system calls which work
* with unicode strings.
*/
- (const char*) fileSystemRepresentationWithPath: (NSString*)path
{
NSString *localPath;
const char *local_c_path = 0;
const _CHAR *c_path = 0;
localPath = [self localFromOpenStepPath: path];
if (localPath
&& [localPath canBeConvertedToEncoding: [NSString defaultCStringEncoding]])
if (path != nil)
{
local_c_path = [localPath cString];
#ifdef __MINGW__
c_path
= (const _CHAR*)[path cStringUsingEncoding: NSUnicodeStringEncoding];
#else
if ([path canBeConvertedToEncoding: [NSString defaultCStringEncoding]])
{
c_path = [path cString];
}
#endif
}
return (local_c_path);
return (const char*)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.
*/
/** Deprecated */
- (NSString*) localFromOpenStepPath: (NSString*)path
{
NSString *newpath = nil;
#ifdef __MINGW__
/*
* If path is in Unix format, transmogrify it so Windows functions
* can handle it
*/
* If path is in Unix format, transmogrify it so Windows functions
* can handle it
*/
int wcount; // count unichars
unichar *wc_path = 0;
int l;
GSOnceMLog(@"deprecated");
path = [path stringByStandardizingPath];
wcount = [path length];
if (wcount != 0)
@ -2010,6 +2023,7 @@ static NSFileManager* defaultManager = nil;
newpath = path;
}
#else
GSOnceMLog(@"deprecated");
/*
* NB ... Don't standardize path, since that would automatically
* follow symbolic links ... and mess up any code wishing to
@ -2024,41 +2038,30 @@ static NSFileManager* defaultManager = nil;
}
/**
* 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.
* This method converts from a local filesystem specific name
* to an NSString object. Use it to convert a filename returned by
* a systemcall into a value for internal use.<br />
* The value of len is the number of bytes of data pointed to by string.<br />
* On windows, the filesystem representation is utf-16.
*/
- (NSString*) stringWithFileSystemRepresentation: (const char*)string
length: (unsigned int)len
{
NSString *localPath = nil;
if (string != 0)
{
localPath = [NSString stringWithCString: string length: len];
}
return([self openStepPathFromLocal: localPath]);
#ifdef __MINGW__
return [NSString stringWithCharacters: (const unichar*)string length: len/2];
#else
return [NSString stringWithCString: string length: len];
#endif
}
/**
* 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.
*/
/** Deprecated */
- (NSString*) openStepPathFromLocal: (NSString*)localPath
{
#ifdef __MINGW__
int len; // count unichars
unichar *wc_path = 0;
GSOnceMLog(@"deprecated");
len = [localPath length];
if (len != 0)
{
@ -2162,6 +2165,8 @@ static NSFileManager* defaultManager = nil;
{
return(@"");
}
#else
GSOnceMLog(@"deprecated");
#endif
return localPath;
@ -2200,8 +2205,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,9 +2226,6 @@ static SEL ospfl = 0;
{
if (self == [NSDirectoryEnumerator class])
{
/* Initialize the default manager which we access directly */
[NSFileManager defaultManager];
ospfl = @selector(openStepPathFromLocal:);
}
}
@ -2243,6 +2243,7 @@ static SEL ospfl = 0;
recurseIntoSubdirectories: (BOOL)recurse
followSymlinks: (BOOL)follow
justContents: (BOOL)justContents
for: (NSFileManager*)mgr
{
//TODO: the justContents flag is currently basically useless and should be
// removed
@ -2251,9 +2252,7 @@ static SEL ospfl = 0;
self = [super init];
_openStepPathFromLocalImp = (NSString *(*)(id, SEL,id))
[defaultManager methodForSelector: ospfl];
_mgr = RETAIN(mgr);
_stack = NSZoneMalloc([self zone], sizeof(GSIArray_t));
GSIArrayInitWithZoneAndCapacity(_stack, [self zone], 64);
@ -2263,7 +2262,7 @@ static SEL ospfl = 0;
_topPath = [[NSString alloc] initWithString: path];
localPath = OS2LOCAL(defaultManager, path);
localPath = OS2LOCAL(_mgr, path);
dir_pointer = _OPENDIR(localPath);
if (dir_pointer)
{
@ -2288,6 +2287,7 @@ static SEL ospfl = 0;
NSZoneFree([self zone], _stack);
DESTROY(_topPath);
DESTROY(_currentFilePath);
DESTROY(_mgr);
[super dealloc];
}
@ -2299,8 +2299,8 @@ static SEL ospfl = 0;
*/
- (NSDictionary*) directoryAttributes
{
return [defaultManager fileAttributesAtPath: _topPath
traverseLink: _flags.isFollowing];
return [_mgr fileAttributesAtPath: _topPath
traverseLink: _flags.isFollowing];
}
/**
@ -2311,8 +2311,8 @@ static SEL ospfl = 0;
*/
- (NSDictionary*) fileAttributes
{
return [defaultManager fileAttributesAtPath: _currentFilePath
traverseLink: _flags.isFollowing];
return [_mgr fileAttributesAtPath: _currentFilePath
traverseLink: _flags.isFollowing];
}
/**
@ -2370,9 +2370,9 @@ 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 = [_mgr
stringWithFileSystemRepresentation: (const char*)dirbuf->d_name
length: 2*wcslen(dirbuf->d_name)];
#else
/* Skip "." and ".." directory entries */
if (strcmp(dirbuf->d_name, ".") == 0
@ -2381,8 +2381,9 @@ static SEL ospfl = 0;
continue;
}
/* Name of file to return */
returnFileName = _openStepPathFromLocalImp(defaultManager, ospfl,
[NSString stringWithCString: dirbuf->d_name]);
returnFileName = [_mgr
stringWithFileSystemRepresentation: dirbuf->d_name
length: strlen(dirbuf->d_name)];
#endif
returnFileName = [dir.path stringByAppendingPathComponent:
returnFileName];
@ -2417,8 +2418,7 @@ static SEL ospfl = 0;
#endif
#endif
{
if (_STAT(OS2LOCAL(defaultManager, _currentFilePath),
&statbuf) != 0)
if (_STAT(OS2LOCAL(_mgr, _currentFilePath), &statbuf) != 0)
{
break;
}
@ -2428,7 +2428,7 @@ static SEL ospfl = 0;
_DIR* dir_pointer;
dir_pointer
= _OPENDIR(OS2LOCAL(defaultManager, _currentFilePath));
= _OPENDIR(OS2LOCAL(_mgr, _currentFilePath));
if (dir_pointer)
{
GSIArrayItem item;

View file

@ -218,32 +218,14 @@ static void ShutdownPathUtilities(void);
static inline NSString*
internalizePathCString(const char *path)
{
unsigned int len;
if (path == 0)
{
return nil;
}
len = strlen(path);
return [MGR() stringWithFileSystemRepresentation: path length: len];
return [NSString stringWithCString: path];
}
/* make sure that the path 's' is in internal format (unix-style) */
static inline NSString*
internalizePath(NSString *s)
{
const char *ptr;
unsigned int len;
if (s == nil)
{
return nil;
}
ptr = [s cString];
len = strlen(ptr);
return [MGR() stringWithFileSystemRepresentation: ptr length: len];
return s;
}
/* Convenience MACRO to ease legibility and coding */

View file

@ -188,6 +188,7 @@ void
_gnu_process_args(int argc, char *argv[], char *env[])
{
CREATE_AUTORELEASE_POOL(arp);
NSString *arg0 = nil;
int i;
if (_gnu_arg_zero != 0)
@ -199,28 +200,42 @@ _gnu_process_args(int argc, char *argv[], char *env[])
{
_gnu_arg_zero = (char*)malloc(strlen(argv[0]) + 1);
strcpy(_gnu_arg_zero, argv[0]);
arg0 = [[NSString alloc] initWithCString: _gnu_arg_zero];
}
else
{
#ifdef __MINGW__
char *buffer;
unichar *buffer;
int buffer_size = 0;
int needed_size = 0;
const char *tmp;
while (needed_size == buffer_size)
{
buffer_size = buffer_size + 256;
buffer = (char*)malloc(buffer_size);
needed_size = GetModuleFileNameA(NULL, buffer, buffer_size);
buffer = (unichar*)malloc(buffer_size * sizeof(unichar));
needed_size = GetModuleFileNameW(NULL, buffer, buffer_size);
if (needed_size < buffer_size)
{
_gnu_arg_zero = buffer;
unsigned i;
for (i = 0; i < needed_size; i++)
{
if (buffer[i] == 0)
{
break;
}
}
arg0 = [[NSString alloc] initWithCharacters: buffer length: i];
}
else
{
free(buffer);
}
}
tmp = [arg0 UTF8String];
_gnu_arg_zero = (char*)malloc(strlen(tmp) + 1);
strcpy(_gnu_arg_zero, tmp);
#else
fprintf(stderr, "Error: for some reason, argv not properly set up "
"during GNUstep base initialization\n");
@ -230,8 +245,7 @@ _gnu_process_args(int argc, char *argv[], char *env[])
/* Getting the process name */
IF_NO_GC(RELEASE(_gnu_processName));
_gnu_processName
= [[NSString stringWithCString: _gnu_arg_zero] lastPathComponent];
_gnu_processName = [arg0 lastPathComponent];
IF_NO_GC(RETAIN(_gnu_processName));
@ -245,8 +259,7 @@ _gnu_process_args(int argc, char *argv[], char *env[])
mySet = [NSMutableSet new];
/* Copy the zero'th argument to the argument list */
str = [NSString stringWithCString: _gnu_arg_zero];
obj_argv[0] = str;
obj_argv[0] = arg0;
for (i = 1; i < argc; i++)
{
@ -262,6 +275,7 @@ _gnu_process_args(int argc, char *argv[], char *env[])
_gnu_arguments = [[NSArray alloc] initWithObjects: obj_argv count: added];
IF_NO_GC(RELEASE(_debug_set));
_debug_set = mySet;
RELEASE(arg0);
}
/* Copy the evironment list */

View file

@ -2795,6 +2795,8 @@ handle_printf_atsign (FILE *stream,
NSMutableData *data;
unichar *uniStr;
GSOnceMLog(@"deprecated ... use cStringUsingEncoding:");
data = [NSMutableData dataWithLength: ([self length] + 1) * sizeof(unichar)];
uniStr = (unichar*)[data mutableBytes];
if (uniStr != 0)
@ -2830,11 +2832,13 @@ 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 />
* NB. under GNUstep you can used this to obtain a nul terminated utf-16
* string (sixteen bit characters) as well as eight bit strings.<br />
* The memory pointed to is not owned by the caller, so the
* caller must copy its contents to keep it.<br />
* Raises an * <code>NSCharacterConversionException</code> if loss of
* Raises an <code>NSCharacterConversionException</code> if loss of
* information would occur during conversion.
*/
- (const char*) cStringUsingEncoding: (NSStringEncoding)encoding
@ -3463,6 +3467,8 @@ static NSFileManager *fm = nil;
*/
- (NSString*) localFromOpenStepPath
{
GSOnceMLog(@"deprecated");
if (fm == nil)
{
fm = RETAIN([NSFileManager defaultManager]);
@ -3471,13 +3477,10 @@ static NSFileManager *fm = nil;
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
{
GSOnceMLog(@"deprecated");
if (fm == nil)
{
fm = RETAIN([NSFileManager defaultManager]);

View file

@ -1084,8 +1084,7 @@ quotedFromString(NSString *aString)
}
lpath = [self _fullLaunchPath];
lpath = [lpath localFromOpenStepPath];
wexecutable = [lpath unicharString];
wexecutable = (const unichar*)[lpath fileSystemRepresentation];
args = [[NSMutableString alloc] initWithString: quotedFromString(lpath)];
arg_enum = [[self arguments] objectEnumerator];
@ -1150,7 +1149,7 @@ quotedFromString(NSString *aString)
hdl = [self standardInput];
if ([hdl isKindOfClass: [NSPipe class]])
{
hdl = [hdl fileHandleForReading];
hdl = [(NSPipe*)hdl fileHandleForReading];
[toClose addObject: hdl];
}
start_info.hStdInput = [hdl nativeHandle];
@ -1158,7 +1157,7 @@ quotedFromString(NSString *aString)
hdl = [self standardOutput];
if ([hdl isKindOfClass: [NSPipe class]])
{
hdl = [hdl fileHandleForWriting];
hdl = [(NSPipe*)hdl fileHandleForWriting];
[toClose addObject: hdl];
}
start_info.hStdOutput = [hdl nativeHandle];
@ -1166,7 +1165,7 @@ quotedFromString(NSString *aString)
hdl = [self standardError];
if ([hdl isKindOfClass: [NSPipe class]])
{
hdl = [hdl fileHandleForWriting];
hdl = [(NSPipe*)hdl fileHandleForWriting];
/*
* If we have the same pipe twice we don't want to close it twice
*/
@ -1184,7 +1183,7 @@ quotedFromString(NSString *aString)
1, /* inherit handles */
CREATE_UNICODE_ENVIRONMENT, /* creation flags */
envp, /* env block */
[[[self currentDirectoryPath] localFromOpenStepPath] unicharString],
(const unichar*)[[self currentDirectoryPath] fileSystemRepresentation],
&start_info,
&procInfo);
NSZoneFree(NSDefaultMallocZone(), w_args);
@ -1346,7 +1345,7 @@ GSCheckTasks()
hdl = [self standardInput];
if ([hdl isKindOfClass: [NSPipe class]])
{
hdl = [hdl fileHandleForReading];
hdl = [(NSPipe*)hdl fileHandleForReading];
[toClose addObject: hdl];
}
idesc = [hdl fileDescriptor];
@ -1354,7 +1353,7 @@ GSCheckTasks()
hdl = [self standardOutput];
if ([hdl isKindOfClass: [NSPipe class]])
{
hdl = [hdl fileHandleForWriting];
hdl = [(NSPipe*)hdl fileHandleForWriting];
[toClose addObject: hdl];
}
odesc = [hdl fileDescriptor];
@ -1362,7 +1361,7 @@ GSCheckTasks()
hdl = [self standardError];
if ([hdl isKindOfClass: [NSPipe class]])
{
hdl = [hdl fileHandleForWriting];
hdl = [(NSPipe*)hdl fileHandleForWriting];
/*
* If we have the same pipe twice we don't want to close it twice
*/