| 59 | } |
| 60 | |
| 61 | string Path::GetExecutablePath() |
| 62 | { |
| 63 | #if defined(_WIN32) |
| 64 | vector<string::value_type> path; |
| 65 | path.resize(MAX_PATH); |
| 66 | GetModuleFileName(NULL, &path.front(), static_cast<DWORD>(path.size())); |
| 67 | while (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { |
| 68 | path.resize(path.size() * 2); |
| 69 | GetModuleFileNameA(NULL, &path.front(), static_cast<DWORD>(path.size())); |
| 70 | } |
| 71 | return string(&path.front()); |
| 72 | #elif defined(__APPLE__) |
| 73 | uint32_t size = 0; |
| 74 | _NSGetExecutablePath(nullptr, &size); |
| 75 | string path; |
| 76 | path.resize(size - 1); |
| 77 | if (_NSGetExecutablePath(&path.front(), &size) == 0) |
| 78 | return path; |
| 79 | return string(); |
| 80 | #else |
| 81 | static const char* proc_self_exe = "/proc/self/exe"; |
| 82 | struct stat st; |
| 83 | if (stat(proc_self_exe, &st) == 0) |
| 84 | { |
| 85 | string path; |
| 86 | path.resize(st.st_size); |
| 87 | if (readlink(proc_self_exe, &path.front(), st.st_size) != -1) |
| 88 | return path; |
| 89 | } |
| 90 | return string(); |
| 91 | #endif |
| 92 | } |
| 93 | |
| 94 | string Path::GetExecutableDirectory() |
| 95 | { |