mainBundle patch fix

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6482 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fedor 2000-04-18 21:34:59 +00:00
parent 1d72e5e27d
commit cd56717be2
6 changed files with 64 additions and 8 deletions

View file

@ -73,6 +73,9 @@ typedef enum {
static NSBundle* _mainBundle = nil;
static NSMapTable* _bundles = NULL;
/* Keep the path to the executable file for finding the main bundle. */
static NSString *_executable_path;
/*
* An empty strings file table for use when localization files can't be found.
*/
@ -252,6 +255,7 @@ _bundle_load_callback(Class theClass, Category *theCategory)
{
NSMutableString *system;
NSString *str;
char *output;
if ((str = [env objectForKey: @"GNUSTEP_TARGET_DIR"]) != nil)
gnustep_target_dir = RETAIN(str);
@ -275,6 +279,18 @@ _bundle_load_callback(Class theClass, Category *theCategory)
mutableCopy]);
[system appendString: @"/Libraries"];
#ifdef HAVE_PROC_FS_EXE_LINK
_executable_path = [[NSFileManager defaultManager]
pathContentOfSymbolicLinkAtPath: @"/proc/self/exe"];
#else
_executable_path =
[[[NSProcessInfo processInfo] arguments] objectAtIndex: 0];
output = objc_find_executable([_executable_path cString]);
NSAssert(output, NSInternalInconsistencyException);
_executable_path = [NSString stringWithCString: output];
OBJC_FREE(output);
#endif
_gnustep_bundle = RETAIN([NSBundle bundleWithPath: system]);
}
}
@ -309,17 +325,10 @@ _bundle_load_callback(Class theClass, Category *theCategory)
[load_lock lock];
if ( !_mainBundle )
{
char *output;
NSString *path, *s;
path = [[[NSProcessInfo processInfo] arguments] objectAtIndex: 0];
output = objc_find_executable([path cString]);
NSAssert(output, NSInternalInconsistencyException);
path = [NSString stringWithCString: output];
OBJC_FREE(output);
/* Strip off the name of the program */
path = [path stringByDeletingLastPathComponent];
path = [_executable_path stringByDeletingLastPathComponent];
/* The executable may not lie in the main bundle directory
so we need to chop off the extra subdirectories, the library