mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 09:41:15 +00:00
Various tidyups
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21283 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
2f39ffd602
commit
d8d03c33f0
1 changed files with 49 additions and 277 deletions
|
@ -202,8 +202,6 @@
|
||||||
|
|
||||||
#define _NUL L'\0'
|
#define _NUL L'\0'
|
||||||
|
|
||||||
#define OS2LOCAL(M,P) (const _CHAR*)[M fileSystemRepresentationWithPath: P]
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define _CHMOD(A,B) chmod(A,B)
|
#define _CHMOD(A,B) chmod(A,B)
|
||||||
|
@ -223,10 +221,9 @@
|
||||||
|
|
||||||
#define _NUL '\0'
|
#define _NUL '\0'
|
||||||
|
|
||||||
#define OS2LOCAL(M,P) [M fileSystemRepresentationWithPath: P]
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define _CCP const _CHAR*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -308,6 +305,7 @@
|
||||||
// Getting the default manager
|
// Getting the default manager
|
||||||
|
|
||||||
static NSFileManager* defaultManager = nil;
|
static NSFileManager* defaultManager = nil;
|
||||||
|
static NSStringEncoding defaultEncoding;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a shared default file manager which may be used throughout an
|
* Returns a shared default file manager which may be used throughout an
|
||||||
|
@ -337,6 +335,11 @@ static NSFileManager* defaultManager = nil;
|
||||||
return defaultManager;
|
return defaultManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (void) initialize
|
||||||
|
{
|
||||||
|
defaultEncoding = [NSString defaultCStringEncoding];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
TEST_RELEASE(_lastError);
|
TEST_RELEASE(_lastError);
|
||||||
|
@ -352,7 +355,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
*/
|
*/
|
||||||
- (BOOL) changeCurrentDirectoryPath: (NSString*)path
|
- (BOOL) changeCurrentDirectoryPath: (NSString*)path
|
||||||
{
|
{
|
||||||
const _CHAR *lpath = OS2LOCAL(self, path);
|
const _CHAR *lpath = [self fileSystemRepresentationWithPath: path];
|
||||||
#if defined(__MINGW__)
|
#if defined(__MINGW__)
|
||||||
return SetCurrentDirectory(lpath) == TRUE ? YES : NO;
|
return SetCurrentDirectory(lpath) == TRUE ? YES : NO;
|
||||||
#else
|
#else
|
||||||
|
@ -378,7 +381,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
{
|
{
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
lpath = OS2LOCAL(defaultManager, path);
|
lpath = [defaultManager fileSystemRepresentationWithPath: path];
|
||||||
|
|
||||||
#ifndef __MINGW__
|
#ifndef __MINGW__
|
||||||
num = [attributes fileOwnerAccountID];
|
num = [attributes fileOwnerAccountID];
|
||||||
|
@ -399,8 +402,9 @@ static NSFileManager* defaultManager = nil;
|
||||||
{
|
{
|
||||||
BOOL ok = NO;
|
BOOL ok = NO;
|
||||||
#ifdef HAVE_PWD_H
|
#ifdef HAVE_PWD_H
|
||||||
struct passwd *pw = getpwnam([str cString]);
|
struct passwd *pw;
|
||||||
|
|
||||||
|
pw = getpwnam([str cStringUsingEncoding: defaultEncoding]);
|
||||||
if (pw != 0)
|
if (pw != 0)
|
||||||
{
|
{
|
||||||
ok = (chown(lpath, pw->pw_uid, -1) == 0);
|
ok = (chown(lpath, pw->pw_uid, -1) == 0);
|
||||||
|
@ -434,8 +438,9 @@ static NSFileManager* defaultManager = nil;
|
||||||
{
|
{
|
||||||
BOOL ok = NO;
|
BOOL ok = NO;
|
||||||
#ifdef HAVE_GRP_H
|
#ifdef HAVE_GRP_H
|
||||||
struct group *gp = getgrnam([str cString]);
|
struct group *gp;
|
||||||
|
|
||||||
|
gp = getgrnam([str cStringUsingEncoding: defaultEncoding]);
|
||||||
if (gp)
|
if (gp)
|
||||||
{
|
{
|
||||||
if (chown(lpath, -1, gp->gr_gid) == 0)
|
if (chown(lpath, -1, gp->gr_gid) == 0)
|
||||||
|
@ -660,7 +665,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
{
|
{
|
||||||
const _CHAR *lpath;
|
const _CHAR *lpath;
|
||||||
|
|
||||||
lpath = OS2LOCAL(self, completePath);
|
lpath = [self fileSystemRepresentationWithPath: completePath];
|
||||||
if (CreateDirectory(lpath, 0) == FALSE)
|
if (CreateDirectory(lpath, 0) == FALSE)
|
||||||
{
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
@ -782,7 +787,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
attributes: (NSDictionary*)attributes
|
attributes: (NSDictionary*)attributes
|
||||||
{
|
{
|
||||||
#if defined(__MINGW__)
|
#if defined(__MINGW__)
|
||||||
const _CHAR *lpath = OS2LOCAL(self, path);
|
const _CHAR *lpath = [self fileSystemRepresentationWithPath: path];
|
||||||
HANDLE fh;
|
HANDLE fh;
|
||||||
DWORD written = 0;
|
DWORD written = 0;
|
||||||
DWORD len = [contents length];
|
DWORD len = [contents length];
|
||||||
|
@ -1019,8 +1024,8 @@ static NSFileManager* defaultManager = nil;
|
||||||
const _CHAR *sourcePath;
|
const _CHAR *sourcePath;
|
||||||
const _CHAR *destPath;
|
const _CHAR *destPath;
|
||||||
|
|
||||||
sourcePath = OS2LOCAL(self, source);
|
sourcePath = [self fileSystemRepresentationWithPath: source];
|
||||||
destPath = OS2LOCAL(self, destination);
|
destPath = [self fileSystemRepresentationWithPath: destination];
|
||||||
|
|
||||||
if ([self fileExistsAtPath: destination] == YES)
|
if ([self fileExistsAtPath: destination] == YES)
|
||||||
{
|
{
|
||||||
|
@ -1171,8 +1176,8 @@ static NSFileManager* defaultManager = nil;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (link([source fileSystemRepresentation],
|
if (link([self fileSystemRepresentationWithPath: source],
|
||||||
[destination fileSystemRepresentation]) < 0)
|
[self fileSystemRepresentationWithPath: destination]) < 0)
|
||||||
{
|
{
|
||||||
if ([self _proceedAccordingToHandler: handler
|
if ([self _proceedAccordingToHandler: handler
|
||||||
forError: @"cannot create hard link"
|
forError: @"cannot create hard link"
|
||||||
|
@ -1211,7 +1216,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
|
|
||||||
[self _sendToHandler: handler willProcessPath: path];
|
[self _sendToHandler: handler willProcessPath: path];
|
||||||
|
|
||||||
lpath = OS2LOCAL(self, path);
|
lpath = [self fileSystemRepresentationWithPath: path];
|
||||||
if (lpath == 0 || *lpath == 0)
|
if (lpath == 0 || *lpath == 0)
|
||||||
{
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
@ -1286,7 +1291,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_RMDIR(OS2LOCAL(self, path)) < 0)
|
if (_RMDIR([self fileSystemRepresentationWithPath: path]) < 0)
|
||||||
{
|
{
|
||||||
return [self _proceedAccordingToHandler: handler
|
return [self _proceedAccordingToHandler: handler
|
||||||
forError: [NSString stringWithCString: GSLastErrorStr (errno)]
|
forError: [NSString stringWithCString: GSLastErrorStr (errno)]
|
||||||
|
@ -1315,7 +1320,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
*/
|
*/
|
||||||
- (BOOL) fileExistsAtPath: (NSString*)path isDirectory: (BOOL*)isDirectory
|
- (BOOL) fileExistsAtPath: (NSString*)path isDirectory: (BOOL*)isDirectory
|
||||||
{
|
{
|
||||||
const _CHAR *lpath = OS2LOCAL(self, path);
|
const _CHAR *lpath = [self fileSystemRepresentationWithPath: path];
|
||||||
|
|
||||||
if (isDirectory != 0)
|
if (isDirectory != 0)
|
||||||
{
|
{
|
||||||
|
@ -1374,7 +1379,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
*/
|
*/
|
||||||
- (BOOL) isReadableFileAtPath: (NSString*)path
|
- (BOOL) isReadableFileAtPath: (NSString*)path
|
||||||
{
|
{
|
||||||
const _CHAR* lpath = OS2LOCAL(self, path);
|
const _CHAR* lpath = [self fileSystemRepresentationWithPath: path];
|
||||||
|
|
||||||
if (lpath == 0 || *lpath == _NUL)
|
if (lpath == 0 || *lpath == _NUL)
|
||||||
{
|
{
|
||||||
|
@ -1410,7 +1415,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
*/
|
*/
|
||||||
- (BOOL) isWritableFileAtPath: (NSString*)path
|
- (BOOL) isWritableFileAtPath: (NSString*)path
|
||||||
{
|
{
|
||||||
const _CHAR* lpath = OS2LOCAL(self, path);
|
const _CHAR* lpath = [self fileSystemRepresentationWithPath: path];
|
||||||
|
|
||||||
if (lpath == 0 || *lpath == _NUL)
|
if (lpath == 0 || *lpath == _NUL)
|
||||||
{
|
{
|
||||||
|
@ -1451,7 +1456,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
*/
|
*/
|
||||||
- (BOOL) isExecutableFileAtPath: (NSString*)path
|
- (BOOL) isExecutableFileAtPath: (NSString*)path
|
||||||
{
|
{
|
||||||
const _CHAR* lpath = OS2LOCAL(self, path);
|
const _CHAR* lpath = [self fileSystemRepresentationWithPath: path];
|
||||||
|
|
||||||
if (lpath == 0 || *lpath == _NUL)
|
if (lpath == 0 || *lpath == _NUL)
|
||||||
{
|
{
|
||||||
|
@ -1497,7 +1502,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
*/
|
*/
|
||||||
- (BOOL) isDeletableFileAtPath: (NSString*)path
|
- (BOOL) isDeletableFileAtPath: (NSString*)path
|
||||||
{
|
{
|
||||||
const _CHAR* lpath = OS2LOCAL(self, path);
|
const _CHAR* lpath = [self fileSystemRepresentationWithPath: path];
|
||||||
|
|
||||||
if (lpath == 0 || *lpath == _NUL)
|
if (lpath == 0 || *lpath == _NUL)
|
||||||
{
|
{
|
||||||
|
@ -1525,7 +1530,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
{
|
{
|
||||||
path = @".";
|
path = @".";
|
||||||
}
|
}
|
||||||
lpath = OS2LOCAL(self, path);
|
lpath = [self fileSystemRepresentationWithPath: path];
|
||||||
|
|
||||||
if (access(lpath, X_OK | W_OK) == 0)
|
if (access(lpath, X_OK | W_OK) == 0)
|
||||||
{
|
{
|
||||||
|
@ -1613,7 +1618,8 @@ static NSFileManager* defaultManager = nil;
|
||||||
{
|
{
|
||||||
NSDictionary *d;
|
NSDictionary *d;
|
||||||
|
|
||||||
d = [GSAttrDictionary attributesAt: OS2LOCAL(self, path) traverseLink: flag];
|
d = [GSAttrDictionary attributesAt:
|
||||||
|
[self fileSystemRepresentationWithPath: path] traverseLink: flag];
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1647,7 +1653,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
};
|
};
|
||||||
DWORD SectorsPerCluster, BytesPerSector, NumberFreeClusters;
|
DWORD SectorsPerCluster, BytesPerSector, NumberFreeClusters;
|
||||||
DWORD TotalNumberClusters;
|
DWORD TotalNumberClusters;
|
||||||
const _CHAR *lpath = OS2LOCAL(self, path);
|
const _CHAR *lpath = [self fileSystemRepresentationWithPath: path];
|
||||||
|
|
||||||
if (!GetDiskFreeSpace(lpath, &SectorsPerCluster,
|
if (!GetDiskFreeSpace(lpath, &SectorsPerCluster,
|
||||||
&BytesPerSector, &NumberFreeClusters, &TotalNumberClusters))
|
&BytesPerSector, &NumberFreeClusters, &TotalNumberClusters))
|
||||||
|
@ -1884,7 +1890,8 @@ static NSFileManager* defaultManager = nil;
|
||||||
* This representation could theoretically vary between filesystems.<br />
|
* This representation could theoretically vary between filesystems.<br />
|
||||||
* On windows, the filesystem representation is utf-16 and is expected to
|
* On windows, the filesystem representation is utf-16 and is expected to
|
||||||
* be used in conjunction with the variants of system calls which work
|
* be used in conjunction with the variants of system calls which work
|
||||||
* with unicode strings.
|
* with unicode strings.<br />
|
||||||
|
* Raises an exception if the character conversion is not possible.
|
||||||
*/
|
*/
|
||||||
- (const char*) fileSystemRepresentationWithPath: (NSString*)path
|
- (const char*) fileSystemRepresentationWithPath: (NSString*)path
|
||||||
{
|
{
|
||||||
|
@ -1893,13 +1900,9 @@ static NSFileManager* defaultManager = nil;
|
||||||
if (path != nil)
|
if (path != nil)
|
||||||
{
|
{
|
||||||
#ifdef __MINGW__
|
#ifdef __MINGW__
|
||||||
c_path
|
c_path = (_CCP)[path cStringUsingEncoding: NSUnicodeStringEncoding];
|
||||||
= (const _CHAR*)[path cStringUsingEncoding: NSUnicodeStringEncoding];
|
|
||||||
#else
|
#else
|
||||||
if ([path canBeConvertedToEncoding: [NSString defaultCStringEncoding]])
|
c_path = (_CCP)[path cStringUsingEncoding: defaultEncoding];
|
||||||
{
|
|
||||||
c_path = [path cString];
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1909,132 +1912,8 @@ static NSFileManager* defaultManager = nil;
|
||||||
/** Deprecated */
|
/** Deprecated */
|
||||||
- (NSString*) localFromOpenStepPath: (NSString*)path
|
- (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;
|
|
||||||
|
|
||||||
GSOnceMLog(@"deprecated");
|
GSOnceMLog(@"deprecated");
|
||||||
path = [path stringByStandardizingPath];
|
return path;
|
||||||
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
|
|
||||||
GSOnceMLog(@"deprecated");
|
|
||||||
/*
|
|
||||||
* 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2050,125 +1929,15 @@ static NSFileManager* defaultManager = nil;
|
||||||
#ifdef __MINGW__
|
#ifdef __MINGW__
|
||||||
return [NSString stringWithCharacters: (const unichar*)string length: len/2];
|
return [NSString stringWithCharacters: (const unichar*)string length: len/2];
|
||||||
#else
|
#else
|
||||||
return [NSString stringWithCString: string length: len];
|
return AUTORELEASE([[NSString allocWithZone: NSDefaultMallocZone()]
|
||||||
|
initWithBytes: string length: len encoding: defaultEncoding]);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Deprecated */
|
/** Deprecated */
|
||||||
- (NSString*) openStepPathFromLocal: (NSString*)localPath
|
- (NSString*) openStepPathFromLocal: (NSString*)localPath
|
||||||
{
|
{
|
||||||
#ifdef __MINGW__
|
|
||||||
int len; // count unichars
|
|
||||||
unichar *wc_path = 0;
|
|
||||||
|
|
||||||
GSOnceMLog(@"deprecated");
|
GSOnceMLog(@"deprecated");
|
||||||
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(@"");
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
GSOnceMLog(@"deprecated");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return localPath;
|
return localPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2262,7 +2031,7 @@ inline void gsedRelease(GSEnumeratedDirectory X)
|
||||||
|
|
||||||
_topPath = [[NSString alloc] initWithString: path];
|
_topPath = [[NSString alloc] initWithString: path];
|
||||||
|
|
||||||
localPath = OS2LOCAL(_mgr, path);
|
localPath = [_mgr fileSystemRepresentationWithPath: path];
|
||||||
dir_pointer = _OPENDIR(localPath);
|
dir_pointer = _OPENDIR(localPath);
|
||||||
if (dir_pointer)
|
if (dir_pointer)
|
||||||
{
|
{
|
||||||
|
@ -2403,8 +2172,8 @@ inline void gsedRelease(GSEnumeratedDirectory X)
|
||||||
#else
|
#else
|
||||||
if (!_flags.isFollowing)
|
if (!_flags.isFollowing)
|
||||||
{
|
{
|
||||||
if (lstat([_currentFilePath fileSystemRepresentation],
|
if (lstat([_mgr fileSystemRepresentationWithPath:
|
||||||
&statbuf) != 0)
|
_currentFilePath], &statbuf) != 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2418,7 +2187,8 @@ inline void gsedRelease(GSEnumeratedDirectory X)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (_STAT(OS2LOCAL(_mgr, _currentFilePath), &statbuf) != 0)
|
if (_STAT([_mgr fileSystemRepresentationWithPath:
|
||||||
|
_currentFilePath], &statbuf) != 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2428,7 +2198,8 @@ inline void gsedRelease(GSEnumeratedDirectory X)
|
||||||
_DIR* dir_pointer;
|
_DIR* dir_pointer;
|
||||||
|
|
||||||
dir_pointer
|
dir_pointer
|
||||||
= _OPENDIR(OS2LOCAL(_mgr, _currentFilePath));
|
= _OPENDIR([_mgr fileSystemRepresentationWithPath:
|
||||||
|
_currentFilePath]);
|
||||||
if (dir_pointer)
|
if (dir_pointer)
|
||||||
{
|
{
|
||||||
GSIArrayItem item;
|
GSIArrayItem item;
|
||||||
|
@ -2644,7 +2415,8 @@ inline void gsedRelease(GSEnumeratedDirectory X)
|
||||||
handler: (id)handler
|
handler: (id)handler
|
||||||
{
|
{
|
||||||
#if defined(__MINGW__)
|
#if defined(__MINGW__)
|
||||||
if (CopyFile(OS2LOCAL(self, source), OS2LOCAL(self, destination), NO))
|
if (CopyFile([self fileSystemRepresentationWithPath: source],
|
||||||
|
[self fileSystemRepresentationWithPath: destination], NO))
|
||||||
{
|
{
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
@ -2900,8 +2672,8 @@ inline void gsedRelease(GSEnumeratedDirectory X)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (link([sourceFile fileSystemRepresentation],
|
if (link([self fileSystemRepresentationWithPath: sourceFile],
|
||||||
[destinationFile fileSystemRepresentation]) < 0)
|
[self fileSystemRepresentationWithPath: destinationFile]) < 0)
|
||||||
{
|
{
|
||||||
if ([self _proceedAccordingToHandler: handler
|
if ([self _proceedAccordingToHandler: handler
|
||||||
forError: @"cannot create hard link"
|
forError: @"cannot create hard link"
|
||||||
|
|
Loading…
Reference in a new issue