Another path fix

This commit is contained in:
rfm 2023-12-19 14:24:13 +00:00
parent cead13c823
commit c739ac81bd
4 changed files with 83 additions and 5 deletions

View file

@ -496,7 +496,8 @@ GSPrivateStrExternalize(GSStr s) GS_ATTRIB_PRIVATE;
* module. So it returns the full filesystem path for shared libraries
* and bundles (which is very nice), but unfortunately it returns
* argv[0] (which might be something as horrible as './obj/test')
* for classes in the main executable.
* for classes in the main executable. In this case we return the
* full path to the executable rather than the value from the linker.
*
* Currently, the function will return nil if any of the following
* conditions is satisfied:

View file

@ -277,11 +277,23 @@ NSString *GSPrivateSymbolPath(Class theClass)
*/
if (0 != dladdr((void*)theClass, &info))
{
NSString *s;
/* On some platforms, when the symbol is in the executable, the
* dladdr() function returns the value from argv[0] as the path.
* So we check for that and map it to the full path of the
* executable.
*/
if (strcmp(info.dli_fname, GSPrivateArgZero()) == 0)
{
return GSPrivateExecutablePath();
}
else
{
NSString *s;
s = [NSString stringWithUTF8String: info.dli_fname];
s = [s stringByResolvingSymlinksInPath];
return [s stringByStandardizingPath];
s = [NSString stringWithUTF8String: info.dli_fname];
s = [s stringByResolvingSymlinksInPath];
return [s stringByStandardizingPath];
}
}
#endif