From c805754c596d380044e5bbd880df054b96106422 Mon Sep 17 00:00:00 2001 From: CaS Date: Tue, 7 May 2002 11:06:22 +0000 Subject: [PATCH] mingw tidyups git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13603 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/NSFileManager.m | 36 ++++++++++++++++++++++++++---------- Source/NSUser.m | 13 ++++++++++--- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5992f6e5a..34eca7de3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2002-05-07 Richard Frith-Macdonald + + * Source/NSUser.m: mingw path fixes and debugging + * Source/NSFileManager.m: ditto + 2002-05-06 Adam Fedor * Source/NSMethodSignature.m (-isEqual:): Implemented (from diff --git a/Source/NSFileManager.m b/Source/NSFileManager.m index 5c2b6256a..13a1233b5 100644 --- a/Source/NSFileManager.m +++ b/Source/NSFileManager.m @@ -1339,10 +1339,11 @@ static NSFileManager* defaultManager = nil; { return 0; } - if (l >= 3 && c_path[0] == '~' && c_path[2] == '/' && isalpha(c_path[1])) + if (l >= 2 && c_path[0] == '~' && isalpha(c_path[1]) + && (l == 2 || c_path[2] == '/')) { newpath = [NSString stringWithFormat: @"%c:%s", c_path[1], - &c_path[2]]; + &c_path[2]]; } else if (l >= 3 && c_path[0] == '/' && c_path[1] == '/' && isalpha(c_path[2])) { @@ -1390,7 +1391,9 @@ static NSFileManager* defaultManager = nil; } } #else - if (l >= 3 && c_path[0] == '/' && c_path[2] == '/' && isalpha(c_path[1])) + if (l >= 2 && c_path[0] == '/' && isalpha(c_path[1]) + && (l == 2 || c_path[2] == '/')) + { /* Mingw /drive/... format */ newpath = [NSString stringWithFormat: @"%c:%s", c_path[1], @@ -1425,6 +1428,7 @@ static NSFileManager* defaultManager = nil; length: (unsigned int)len { #ifdef __MINGW__ + const char *ptr = string; char buf[len + 20]; unsigned i; unsigned j; @@ -1437,26 +1441,36 @@ static NSFileManager* defaultManager = nil; { return @""; } - if (len >= 2 && string[1] == ':' && isalpha(string[0])) + if (len >= 2 && ptr[1] == ':' && isalpha(ptr[0])) { /* * Convert ':' to '~/' sequences. */ buf[0] = '~'; - buf[1] = string[0]; + buf[1] = ptr[0]; buf[2] = '/'; - string--; + ptr -= 1; len++; i = 3; } #ifdef __CYGWIN__ - else if (len > 9 && strncmp(string, "/cygdrive/", 10) == 0) + else if (len > 9 && strncmp(ptr, "/cygdrive/", 10) == 0) { buf[0] = '~'; - string += 9; + ptr += 9; len -= 9; i = 1; } +#else + else if (len >= 2 && ptr[0] == '/' && isalpha(ptr[1]) + && (len == 2 || ptr[2] == '/')) + { + /* + * Convert '/' to '~' sequences. + */ + buf[0] = '~'; + i = 1; + } #endif else { @@ -1469,7 +1483,7 @@ static NSFileManager* defaultManager = nil; j = i; while (i < len) { - if (string[i] == '\\') + if (ptr[i] == '\\') { if (j == 0 || buf[j-1] != '/') { @@ -1485,10 +1499,12 @@ static NSFileManager* defaultManager = nil; } else { - buf[j++] = string[i]; + buf[j++] = ptr[i]; } i++; } + buf[j] = '\0'; +// NSLog(@"Map '%s' to '%s'", string, buf); return [NSString stringWithCString: buf length: j]; #endif return [NSString stringWithCString: string length: len]; diff --git a/Source/NSUser.m b/Source/NSUser.m index 8e21f0205..aab1fab28 100644 --- a/Source/NSUser.m +++ b/Source/NSUser.m @@ -144,9 +144,9 @@ NSUserName(void) char buf[1024]; DWORD n = 1024; - if (GetEnvironmentVariable("LOGNAME", buf, 1024)) + if (GetEnvironmentVariable("LOGNAME", buf, 1024) != 0 && buf[0] != '\0') loginName = buf; - else if (GetUserName(buf, &n)) + else if (GetUserName(buf, &n) != 0 && buf[0] != '\0') loginName = buf; #else loginName = getenv("LOGNAME"); @@ -268,8 +268,15 @@ NSHomeDirectoryForUser(NSString *loginName) } [gnustep_global_lock unlock]; } + if ([s length] == 0 && [loginName length] != 1) + { + s = nil; + NSLog(@"NSHomeDirectoryForUser(%@) failed", loginName); + } #endif - return ImportPath(s, 0); + s = ImportPath(s, 0); +// NSLog(@"Home for %@ is %@", loginName, s); + return s; } /**