| 262 | #endif |
| 263 | |
| 264 | std::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 | |
| 290 | std::string GetExecutableDirectory() { |
| 291 | return Dirname(GetExecutablePath()); |
no test coverage detected