From b7a18b3278a150688f471a738b31d06fe4594bdc Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 31 Dec 2017 09:55:23 -0800 Subject: [PATCH] Added method to derive application path for MacOS (/proc isn't there on MacOS) --- src/lay/lay/laySystemPaths.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lay/lay/laySystemPaths.cc b/src/lay/lay/laySystemPaths.cc index 6e458716c..2f5645c32 100644 --- a/src/lay/lay/laySystemPaths.cc +++ b/src/lay/lay/laySystemPaths.cc @@ -30,6 +30,9 @@ #ifdef _WIN32 # include +#elif __APPLE__ +# include +# include #else # include #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 ())));