From ddf52b8752a926629f002077b29556101efeb8f7 Mon Sep 17 00:00:00 2001 From: rfm Date: Wed, 5 Mar 2008 09:32:49 +0000 Subject: [PATCH] guess what caller meant when they give us bad path name git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26197 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/NSBundle.m | 33 +++++++++++++++++++++++++++- Testing/basic.m | 56 ++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 85 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2b7edbd4a..7e46d48f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-03-05 Richard Frith-Macdonald + + * Source/NSBundle.m Make better guess at what the caller meant when + they give us a non-absolute path name on mingw. + 2008-03-03 Richard Frith-Macdonald * Source/NSNull.m: Make result of description method match MacOSX diff --git a/Source/NSBundle.m b/Source/NSBundle.m index 7be34ec98..488de2830 100644 --- a/Source/NSBundle.m +++ b/Source/NSBundle.m @@ -1231,8 +1231,39 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory) { NSWarnMLog(@"NSBundle -initWithPath: requires absolute path names, " @"given '%@'", path); + +#if defined(__MINGW32__) + if ([path length] > 0 && + ([path characterAtIndex: 0]=='/' || [path characterAtIndex: 0]=='\\')) + { + NSString *root; + unsigned length; + + /* The path has a leading path separator, so we try assuming + * that it's a path on the current filesystem, and append it + * to the filesystem root. + */ + root = [[NSFileManager defaultManager] currentDirectoryPath]; + length = [root length]; + root = [root stringByDeletingLastPathComponent]; + while ([root length] != length) + { + length = [root length]; + root = [root stringByDeletingLastPathComponent]; + } + path = [root stringByAppendingPathComponent: path]; + } + else + { + /* Try appending to the current working directory. + */ + path = [[[NSFileManager defaultManager] currentDirectoryPath] + stringByAppendingPathComponent: path]; + } +#else path = [[[NSFileManager defaultManager] currentDirectoryPath] - stringByAppendingPathComponent: path]; + stringByAppendingPathComponent: path]; +#endif } /* diff --git a/Testing/basic.m b/Testing/basic.m index f7b34ed77..1d6949dab 100644 --- a/Testing/basic.m +++ b/Testing/basic.m @@ -1,8 +1,48 @@ -#include -int main () -{ - static unsigned char bytes[9] = {'\355', '\264', '\200', '\346', '\224', '\200', '\347', '\214', '\200'}; - NSString *s = [[NSString alloc] initWithBytes: bytes length: 9 encoding: NSUTF8StringEncoding]; - NSLog(@"s %@", s); - return 0; -} +/* Demonstration of windows NSTask launching bug */ + +#include "Foundation/Foundation.h" + +int main() +{ + CREATE_AUTORELEASE_POOL(arp); + + NSTask *task; + NSProcessInfo *info; + NSDictionary *env; + NSString *path; + + info = [NSProcessInfo processInfo]; + env = [info environment]; + +#if defined(__MINGW32__) + path = @"C:\\WINDOWS\\system32\\net.exe"; +// path = @"E:\\WINNT\\system32\\net.exe"; +#else + path = @"/bin/ls"; +#endif + printf("Determined command to run as '%s'\n",[path lossyCString]); + + task = [NSTask launchedTaskWithLaunchPath: path + arguments: [NSArray array]]; + [task waitUntilExit]; + + printf("First task has completed\n"); + + +#if defined(__MINGW32__) + path = @"C:\\WINDOWS\\system32\\mem.exe"; +// path = @"E:\\WINNT\\system32\\mem.exe"; +#else + path = @"/bin/ls"; +#endif + printf("Determined command to run as '%s'\n",[path lossyCString]); + + task = [NSTask launchedTaskWithLaunchPath: path + arguments: [NSArray array]]; + [task waitUntilExit]; + + printf("Second task has completed\n"); + + DESTROY(arp); + return 0; +}