MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / GetExecutablePath

Function GetExecutablePath

Bcore/src/main/cpp/android-base/file.cpp:264–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262#endif
263
264std::string GetExecutablePath() {
265#if defined(__linux__)
266 std::string path;
267 android_lkchan::base::Readlink("/proc/self/exe", &path);
268 return path;
269#elif defined(__APPLE__)
270 char path[PATH_MAX + 1];
271 uint32_t path_len = sizeof(path);
272 int rc = _NSGetExecutablePath(path, &path_len);
273 if (rc < 0) {
274 std::unique_ptr<char> path_buf(new char[path_len]);
275 _NSGetExecutablePath(path_buf.get(), &path_len);
276 return path_buf.get();
277 }
278 return path;
279#elif defined(_WIN32)
280 char path[PATH_MAX + 1];
281 DWORD result = GetModuleFileName(NULL, path, sizeof(path) - 1);
282 if (result == 0 || result == sizeof(path) - 1) return "";
283 path[PATH_MAX - 1] = 0;
284 return path;
285#else
286#error unknown OS
287#endif
288}
289
290std::string GetExecutableDirectory() {
291 return Dirname(GetExecutablePath());

Callers 1

GetExecutableDirectoryFunction · 0.85

Calls 2

ReadlinkFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected