Added method to derive application path for MacOS (/proc isn't there on MacOS)

This commit is contained in:
Matthias Koefferlein 2017-12-31 09:55:23 -08:00
parent 48a6b4b57a
commit b7a18b3278
1 changed files with 12 additions and 0 deletions

View File

@ -30,6 +30,9 @@
#ifdef _WIN32
# include <windows.h>
#elif __APPLE__
# include <libproc.h>
# include <unistd.h>
#else
# include <unistd.h>
#endif
@ -79,6 +82,15 @@ get_inst_path_internal ()
return tl::to_string (fi.absolutePath ());
}
#elif __APPLE__
char buffer[PROC_PIDPATHINFO_MAXSIZE];
int ret = proc_pidpath (getpid (), buffer, sizeof (buffer));
if (ret > 0) {
// TODO: does this correctly translate paths? (MacOS uses UTF-8 encoding with D-like normalization)
return tl::to_string (QFileInfo (QString::fromUtf8 (buffer)).absolutePath ());
}
#else
QFileInfo proc_exe (tl::to_qstring (tl::sprintf ("/proc/%d/exe", getpid ())));