mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-21 04:32:03 +00:00
Minor fixes for cygwin
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3580 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d4f2f56b87
commit
205e47ed25
3 changed files with 81 additions and 91 deletions
|
@ -104,14 +104,10 @@ static BOOL debug = NO;
|
||||||
|
|
||||||
return interval;
|
return interval;
|
||||||
#else
|
#else
|
||||||
TIME_ZONE_INFORMATION sys_time_zone;
|
|
||||||
SYSTEMTIME sys_time;
|
SYSTEMTIME sys_time;
|
||||||
NSCalendarDate *d;
|
NSCalendarDate *d;
|
||||||
NSTimeInterval t;
|
NSTimeInterval t;
|
||||||
|
|
||||||
// Get the time zone information
|
|
||||||
GetTimeZoneInformation(&sys_time_zone);
|
|
||||||
|
|
||||||
// Get the system time
|
// Get the system time
|
||||||
GetLocalTime(&sys_time);
|
GetLocalTime(&sys_time);
|
||||||
|
|
||||||
|
@ -123,10 +119,10 @@ static BOOL debug = NO;
|
||||||
hour: sys_time.wHour
|
hour: sys_time.wHour
|
||||||
minute: sys_time.wMinute
|
minute: sys_time.wMinute
|
||||||
second: sys_time.wSecond
|
second: sys_time.wSecond
|
||||||
timeZone: [NSTimeZone defaultTimeZone]];
|
timeZone: [NSTimeZone localTimeZone]];
|
||||||
t = [d timeIntervalSinceReferenceDate];
|
t = [d timeIntervalSinceReferenceDate];
|
||||||
[d release];
|
[d release];
|
||||||
return t;
|
return t + sys_time.wMilliseconds / 1000.0;
|
||||||
#endif /* __WIN32__ */
|
#endif /* __WIN32__ */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
attributes:(NSDictionary*)attributes
|
attributes:(NSDictionary*)attributes
|
||||||
{
|
{
|
||||||
#if defined(__WIN32__) || defined(_WIN32)
|
#if defined(__WIN32__) || defined(_WIN32)
|
||||||
return CreateDirectory([path cString], NULL);
|
return CreateDirectory([self fileSystemRepresentationWithPath: path], NULL);
|
||||||
#else
|
#else
|
||||||
const char* cpath;
|
const char* cpath;
|
||||||
char dirpath[PATH_MAX+1];
|
char dirpath[PATH_MAX+1];
|
||||||
|
@ -536,7 +536,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
- (BOOL)fileExistsAtPath:(NSString*)path isDirectory:(BOOL*)isDirectory
|
- (BOOL)fileExistsAtPath:(NSString*)path isDirectory:(BOOL*)isDirectory
|
||||||
{
|
{
|
||||||
#if defined(__WIN32__) || defined(_WIN32)
|
#if defined(__WIN32__) || defined(_WIN32)
|
||||||
DWORD res = GetFileAttributes([path cString]);
|
DWORD res = GetFileAttributes([self fileSystemRepresentationWithPath: path]);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
|
@ -1099,6 +1099,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
[currentFileName release];
|
[currentFileName release];
|
||||||
[currentFilePath release];
|
[currentFilePath release];
|
||||||
[topPath release];
|
[topPath release];
|
||||||
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getting attributes
|
// Getting attributes
|
||||||
|
|
|
@ -99,20 +99,32 @@
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static Class NSString_class; /* For speed */
|
||||||
|
|
||||||
|
static unichar pathSepChar = (unichar)'/';
|
||||||
|
static NSString *pathSepString = @"/";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We can't have a 'pathSeps' variable initialized in the +initialize
|
||||||
|
* method 'cos that would cause recursion.
|
||||||
|
*/
|
||||||
|
static NSCharacterSet*
|
||||||
|
pathSeps()
|
||||||
|
{
|
||||||
|
static NSCharacterSet *pathSeps = nil;
|
||||||
|
|
||||||
|
if (pathSeps == nil)
|
||||||
|
{
|
||||||
#if defined(__WIN32__) || defined(_WIN32)
|
#if defined(__WIN32__) || defined(_WIN32)
|
||||||
|
pathSeps = [NSCharacterSet characterSetWithCharactersInString: @"/\\"];
|
||||||
#define PATH_COMPONENT @"\\"
|
|
||||||
#define PATH_COMPONENT_LEN 1
|
|
||||||
#define PATH_COMPONENT2 @"/"
|
|
||||||
#define PATH_COMPONENT_LEN2 1
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
pathSeps = [NSCharacterSet characterSetWithCharactersInString: @"/"];
|
||||||
|
#endif
|
||||||
|
[pathSeps retain];
|
||||||
|
}
|
||||||
|
return pathSeps;
|
||||||
|
}
|
||||||
|
|
||||||
#define PATH_COMPONENT @"/"
|
|
||||||
#define PATH_COMPONENT_LEN 1
|
|
||||||
|
|
||||||
#endif /* Path components */
|
|
||||||
|
|
||||||
@implementation NSString
|
@implementation NSString
|
||||||
|
|
||||||
|
@ -231,6 +243,7 @@ handle_printf_atsign (FILE *stream,
|
||||||
if (self == [NSString class])
|
if (self == [NSString class])
|
||||||
{
|
{
|
||||||
_DefaultStringEncoding = GetDefEncoding();
|
_DefaultStringEncoding = GetDefEncoding();
|
||||||
|
NSString_class = self;
|
||||||
NSString_concrete_class = [NSGString class];
|
NSString_concrete_class = [NSGString class];
|
||||||
NSString_c_concrete_class = [NSGCString class];
|
NSString_c_concrete_class = [NSGCString class];
|
||||||
NSMutableString_concrete_class = [NSGMutableString class];
|
NSMutableString_concrete_class = [NSGMutableString class];
|
||||||
|
@ -1456,7 +1469,7 @@ else
|
||||||
Class c = fastClassOfInstance(anObject);
|
Class c = fastClassOfInstance(anObject);
|
||||||
|
|
||||||
if (c != nil) {
|
if (c != nil) {
|
||||||
if (fastClassIsKindOfClass(c, _fastCls._NSString)) {
|
if (fastClassIsKindOfClass(c, NSString_class)) {
|
||||||
return [self isEqualToString: anObject];
|
return [self isEqualToString: anObject];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2246,10 +2259,10 @@ else
|
||||||
NSRange range;
|
NSRange range;
|
||||||
NSString *substring = nil;
|
NSString *substring = nil;
|
||||||
|
|
||||||
range = [self rangeOfString: PATH_COMPONENT options:NSBackwardsSearch];
|
range = [self rangeOfCharacterFromSet: pathSeps() options: NSBackwardsSearch];
|
||||||
if (range.length == 0)
|
if (range.length == 0)
|
||||||
substring = [[self copy] autorelease];
|
substring = [[self copy] autorelease];
|
||||||
else if (range.location == ([self length] - PATH_COMPONENT_LEN))
|
else if (range.location == ([self length] - 1))
|
||||||
{
|
{
|
||||||
if (range.location == 0)
|
if (range.location == 0)
|
||||||
substring = [[NSString new] autorelease];
|
substring = [[NSString new] autorelease];
|
||||||
|
@ -2258,28 +2271,7 @@ else
|
||||||
lastPathComponent];
|
lastPathComponent];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
substring = [self substringFromIndex:range.location + PATH_COMPONENT_LEN];
|
substring = [self substringFromIndex:range.location + 1];
|
||||||
|
|
||||||
#ifdef PATH_COMPONENT2
|
|
||||||
if (substring == self)
|
|
||||||
{
|
|
||||||
NSRange range2 = [self rangeOfString: PATH_COMPONENT2
|
|
||||||
options:NSBackwardsSearch];
|
|
||||||
if (range2.length == 0)
|
|
||||||
substring = [[self copy] autorelease];
|
|
||||||
else if (range2.location == ([self length] - PATH_COMPONENT_LEN2))
|
|
||||||
{
|
|
||||||
if (range2.location == 0)
|
|
||||||
substring = [[NSString new] autorelease];
|
|
||||||
else
|
|
||||||
substring = [[self substringToIndex:range2.location]
|
|
||||||
lastPathComponent];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
substring = [self substringFromIndex:
|
|
||||||
range2.location + PATH_COMPONENT_LEN2];
|
|
||||||
}
|
|
||||||
#endif /* PATH_COMPONENT2 */
|
|
||||||
|
|
||||||
return substring;
|
return substring;
|
||||||
}
|
}
|
||||||
|
@ -2295,24 +2287,11 @@ else
|
||||||
|
|
||||||
range = [self rangeOfString:@"." options:NSBackwardsSearch];
|
range = [self rangeOfString:@"." options:NSBackwardsSearch];
|
||||||
if (range.length == 0
|
if (range.length == 0
|
||||||
|| range.location < ([self rangeOfString: PATH_COMPONENT
|
|| range.location < ([self rangeOfCharacterFromSet: pathSeps()
|
||||||
options: NSBackwardsSearch]).location)
|
options: NSBackwardsSearch]).location)
|
||||||
substring = nil;
|
substring = nil;
|
||||||
else
|
else
|
||||||
substring = [self substringFromIndex:range.location + PATH_COMPONENT_LEN];
|
substring = [self substringFromIndex:range.location + 1];
|
||||||
|
|
||||||
#ifdef PATH_COMPONENT2
|
|
||||||
if (!substring)
|
|
||||||
{
|
|
||||||
if (range.length == 0
|
|
||||||
|| range.location < ([self rangeOfString: PATH_COMPONENT2
|
|
||||||
options:NSBackwardsSearch]).location)
|
|
||||||
substring = nil;
|
|
||||||
else
|
|
||||||
substring = [self substringFromIndex:
|
|
||||||
range.location + PATH_COMPONENT_LEN2];
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!substring)
|
if (!substring)
|
||||||
substring = [[NSString new] autorelease];
|
substring = [[NSString new] autorelease];
|
||||||
|
@ -2331,15 +2310,15 @@ else
|
||||||
if ([aString length] == 0)
|
if ([aString length] == 0)
|
||||||
return [[self copy] autorelease];
|
return [[self copy] autorelease];
|
||||||
|
|
||||||
range = [aString rangeOfString:@"/"];
|
range = [aString rangeOfCharacterFromSet: pathSeps()];
|
||||||
if (range.length != 0 && range.location == 0)
|
if (range.length != 0 && range.location == 0)
|
||||||
[NSException raise: NSGenericException
|
[NSException raise: NSGenericException
|
||||||
format: @"attempt to append illegal path component"];
|
format: @"attempt to append illegal path component"];
|
||||||
|
|
||||||
range = [self rangeOfString:@"/" options:NSBackwardsSearch];
|
range = [self rangeOfCharacterFromSet: pathSeps() options: NSBackwardsSearch];
|
||||||
if ((range.length == 0 || range.location != [self length] - 1) && [self length] > 0)
|
if ((range.length == 0 || range.location != [self length] - 1) && [self length] > 0)
|
||||||
|
|
||||||
newstring = [self stringByAppendingString:@"/"];
|
newstring = [self stringByAppendingString: pathSepString];
|
||||||
else
|
else
|
||||||
newstring = self;
|
newstring = self;
|
||||||
|
|
||||||
|
@ -2389,7 +2368,7 @@ else
|
||||||
else if (range.location > 1)
|
else if (range.location > 1)
|
||||||
substring = [self substringToIndex:range.location-1];
|
substring = [self substringToIndex:range.location-1];
|
||||||
else
|
else
|
||||||
substring = PATH_COMPONENT;
|
substring = pathSepString;
|
||||||
return substring;
|
return substring;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2419,7 +2398,7 @@ else
|
||||||
if ([self characterAtIndex: 0] != 0x007E)
|
if ([self characterAtIndex: 0] != 0x007E)
|
||||||
return [[self copy] autorelease];
|
return [[self copy] autorelease];
|
||||||
|
|
||||||
first_slash_range = [self rangeOfString: @"/"];
|
first_slash_range = [self rangeOfString: pathSepString];
|
||||||
|
|
||||||
if (first_slash_range.location != 1)
|
if (first_slash_range.location != 1)
|
||||||
{
|
{
|
||||||
|
@ -2453,7 +2432,7 @@ else
|
||||||
if (![self hasPrefix: homedir])
|
if (![self hasPrefix: homedir])
|
||||||
return [[self copy] autorelease];
|
return [[self copy] autorelease];
|
||||||
|
|
||||||
return [NSString stringWithFormat: @"~/%@",
|
return [NSString stringWithFormat: @"~%c%@", (char)pathSepChar,
|
||||||
[self substringFromIndex: [homedir length] + 1]];
|
[self substringFromIndex: [homedir length] + 1]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2507,9 +2486,10 @@ else
|
||||||
|
|
||||||
/* BREAK CONDITION */
|
/* BREAK CONDITION */
|
||||||
if ([first_half length] == 0) break;
|
if ([first_half length] == 0) break;
|
||||||
else if ([first_half isEqual: @"/"])
|
else if ([first_half length] == 1
|
||||||
|
&& [pathSeps() characterIsMember: [first_half characterAtIndex: 0]])
|
||||||
{
|
{
|
||||||
second_half = [@"/" stringByAppendingPathComponent: second_half];
|
second_half = [pathSepString stringByAppendingPathComponent: second_half];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2530,28 +2510,41 @@ else
|
||||||
[s deleteCharactersInRange: ((NSRange){0,7})];
|
[s deleteCharactersInRange: ((NSRange){0,7})];
|
||||||
|
|
||||||
/* Condense `//' */
|
/* Condense `//' */
|
||||||
while ((r = [s rangeOfString: @"//"]).length)
|
while ((r = [s rangeOfCharacterFromSet: pathSeps()]).length
|
||||||
|
&& r.location + r.length < [s length]
|
||||||
|
&& [pathSeps() characterIsMember: [s characterAtIndex: r.location + 1]])
|
||||||
[s deleteCharactersInRange: r];
|
[s deleteCharactersInRange: r];
|
||||||
|
|
||||||
/* Condense `/./' */
|
/* Condense `/./' */
|
||||||
while ((r = [s rangeOfString: @"/./"]).length)
|
while ((r = [s rangeOfCharacterFromSet: pathSeps()]).length
|
||||||
|
&& r.location + r.length < [s length] + 1
|
||||||
|
&& [s characterAtIndex: r.location + 1] == (unichar)'.'
|
||||||
|
&& [pathSeps() characterIsMember: [s characterAtIndex: r.location + 2]])
|
||||||
{
|
{
|
||||||
r.length--;
|
r.length++;
|
||||||
[s deleteCharactersInRange: r];
|
[s deleteCharactersInRange: r];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Condense `/../' */
|
/* Condense `/../' */
|
||||||
while ((r = [s rangeOfString: @"/../"]).length)
|
while ((r = [s rangeOfCharacterFromSet: pathSeps()]).length
|
||||||
|
&& r.location + r.length < [s length] + 2
|
||||||
|
&& [s characterAtIndex: r.location + 1] == (unichar)'.'
|
||||||
|
&& [s characterAtIndex: r.location + 2] == (unichar)'.'
|
||||||
|
&& [pathSeps() characterIsMember: [s characterAtIndex: r.location + 3]])
|
||||||
{
|
{
|
||||||
NSRange r2 = {0, r.length-1};
|
if (r.location > 0)
|
||||||
r = [s rangeOfString: @"/"
|
{
|
||||||
|
NSRange r2 = {0, r.location};
|
||||||
|
r = [s rangeOfCharacterFromSet: pathSeps()
|
||||||
options: NSBackwardsSearch
|
options: NSBackwardsSearch
|
||||||
range: r2];
|
range: r2];
|
||||||
|
if (r.length == 0)
|
||||||
|
r = r2;
|
||||||
r.length += 4; /* Add the `/../' */
|
r.length += 4; /* Add the `/../' */
|
||||||
|
}
|
||||||
[s deleteCharactersInRange: r];
|
[s deleteCharactersInRange: r];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* xxx Should we not return a mutable string? */
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue