MCPcopy Create free account
hub / github.com/AdaptiveCpp/AdaptiveCpp / get_this_executable_path

Function get_this_executable_path

src/common/filesystem.cpp:94–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92
93
94std::string get_this_executable_path(std::string* filename,
95 std::string* directory) {
96 auto get_path = []() -> std::string{
97#ifndef _WIN32
98 char result[PATH_MAX];
99 ssize_t num_read = readlink("/proc/self/exe", result, PATH_MAX);
100 if (num_read >= 0 && num_read <= PATH_MAX - 1) {
101 result[num_read] = '\0';
102 return std::string{result};
103 }
104 return std::string{};
105#else
106 std::vector<char> path_buff;
107 DWORD copied = 0;
108 do {
109 path_buff.resize(path_buff.size() + MAX_PATH);
110 copied = GetModuleFileNameA(0, path_buff.data(), path_buff.size());
111 } while (copied >= path_buff.size());
112
113 path_buff.resize(copied);
114
115 return std::string{path_buff.begin(), path_buff.end()};
116#endif
117 };
118
119 std::string path = get_path();
120 if(filename)
121 *filename = path.empty() ? "" : fs::path{path}.filename().string();
122 if(directory)
123 *directory = path.empty() ? "" : fs::path{path}.parent_path().string();
124 return path;
125}
126
127std::string join_path(const std::string& base, const std::string& extra) {
128 return (fs::path(base) / extra).string();

Callers 2

settings_config_fileMethod · 0.85
persistent_storageMethod · 0.85

Calls 4

sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected