Browse Source

Improve posix getExecutableFile()

Signed-off-by: falkTX <falktx@falktx.com>
develop-distrho
falkTX 3 years ago
parent
commit
ec2297fc2a
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
1 changed files with 29 additions and 2 deletions
  1. +29
    -2
      modules/juce_core/native/juce_SharedCode_posix.h

+ 29
- 2
modules/juce_core/native/juce_SharedCode_posix.h View File

@@ -616,12 +616,39 @@ File juce_getExecutableFile()
auto localSymbol = (void*) juce_getExecutableFile;
dladdr (localSymbol, &exeInfo);
return CharPointer_UTF8 (exeInfo.dli_fname);
const CharPointer_UTF8 filename (exeInfo.dli_fname);
// if the filename is absolute simply return it
if (File::isAbsolutePath (filename))
return filename;
// if the filename is relative construct from CWD
if (filename[0] == '.')
return File::getCurrentWorkingDirectory().getChildFile (filename).getFullPathName();
// filename is abstract, look up in PATH
if (const char* const envpath = ::getenv ("PATH"))
{
StringArray paths (StringArray::fromTokens (envpath, ":", ""));
for (int i=paths.size(); --i>=0;)
{
const File filepath (File (paths[i]).getChildFile (filename));
if (filepath.existsAsFile())
return filepath.getFullPathName();
}
}
// if we reach this, we failed to find ourselves...
jassertfalse;
return filename;
}
};
static String filename = DLAddrReader::getFilename();
return File::getCurrentWorkingDirectory().getChildFile (filename);
return filename;
}
//==============================================================================


Loading…
Cancel
Save