File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ namespace util
1616 */
1717std::string binaryPathToInstallDir (const char * path);
1818
19+ /* *
20+ * @brief Find the directory where a CodeCompass binary is being run from.
21+ * @return The absolute path of the directory where the binary is located.
22+ */
23+ std::string findCurrentExecutableDir ();
24+
1925} // namespace util
2026} // namespace cc
2127
Original file line number Diff line number Diff line change 11#include < cstdlib>
2+ #include < climits>
3+ #include < unistd.h>
24
35#include < boost/filesystem.hpp>
46
@@ -50,5 +52,17 @@ std::string binaryPathToInstallDir(const char* path)
5052 throw std::runtime_error (std::string (" Could not find " ) + path + std::string (" ." ));
5153}
5254
55+ std::string findCurrentExecutableDir ()
56+ {
57+ char exePath[PATH_MAX];
58+ ssize_t len = ::readlink (" /proc/self/exe" , exePath, sizeof (exePath));
59+
60+ if (len == -1 || len == sizeof (exePath))
61+ len = 0 ;
62+
63+ exePath[len] = ' \0 ' ;
64+ return fs::path (exePath).parent_path ().string ();
65+ }
66+
5367} // namespace util
5468} // namespace cc
You can’t perform that action at this time.
0 commit comments