Add "get executable's path" function

pull/41/head
jackun 4 years ago
parent 74c9803087
commit 90a93fd2fc
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -98,3 +98,10 @@ bool dir_exists(const std::string& path)
struct stat s;
return !stat(path.c_str(), &s) && S_ISDIR(s.st_mode);
}
std::string get_exe_path()
{
char result[PATH_MAX] {};
ssize_t count = readlink("/proc/self/exe", result, PATH_MAX);
return std::string(result, (count > 0) ? count : 0);
}

@ -15,3 +15,4 @@ bool find_folder(const std::string& root, const std::string& prefix, std::string
std::vector<std::string> ls(const char* root, const char* prefix = nullptr, LS_FLAGS flags = LS_DIRS);
bool file_exists(const std::string& path);
bool dir_exists(const std::string& path);
std::string get_exe_path();

Loading…
Cancel
Save