From 8fd938e142a42bfd13c850a08f7e49b73a3a0fce Mon Sep 17 00:00:00 2001 From: Soonho Kong Date: Wed, 10 Sep 2014 07:38:49 -0700 Subject: [PATCH] fix(util/lean_path.cpp): get_exe_location follows symbolic link in OSX Previously, we had different behaviors on Linux and OSX when get_exe_location finds a location of executable: - Linux: follow symbolic link - OSX: not follow symbolic link --- src/util/lean_path.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/util/lean_path.cpp b/src/util/lean_path.cpp index 0cfd3c99ad..d2d12fc573 100644 --- a/src/util/lean_path.cpp +++ b/src/util/lean_path.cpp @@ -52,15 +52,19 @@ static std::string get_exe_location() { // OSX version #include #include +#include static char g_path_sep = ':'; static char g_sep = '/'; static char g_bad_sep = '\\'; static std::string get_exe_location() { - char buf[PATH_MAX]; + char buf1[PATH_MAX]; + char buf2[PATH_MAX]; uint32_t bufsize = PATH_MAX; - if (_NSGetExecutablePath(buf, &bufsize) != 0) + if (_NSGetExecutablePath(buf1, &bufsize) != 0) throw exception("failed to locate Lean executable location"); - return std::string(buf); + if (!realpath(buf1, buf2)) + throw exception("failed to resolve symbolic links in " + std::string(buf1)); + return std::string(buf2); } #else // Linux version