Returns the absolute path to the current executable. Compared to argv[0], this path can always be used to locate the Jazzer JAR next to it, even when Jazzer is executed from PATH.
| 61 | // this path can always be used to locate the Jazzer JAR next to it, even when |
| 62 | // Jazzer is executed from PATH. |
| 63 | std::string getExecutablePath() { |
| 64 | char buf[655536]; |
| 65 | #if defined(__APPLE__) |
| 66 | uint32_t buf_size = sizeof(buf); |
| 67 | uint32_t read_bytes = buf_size - 1; |
| 68 | bool failed = (_NSGetExecutablePath(buf, &buf_size) != 0); |
| 69 | #elif defined(_WIN32) |
| 70 | DWORD read_bytes = GetModuleFileNameA(NULL, buf, sizeof(buf)); |
| 71 | bool failed = (read_bytes == 0); |
| 72 | #elif defined(__ANDROID__) |
| 73 | bool failed = true; |
| 74 | uint32_t read_bytes = 0; |
| 75 | #else // Assume Linux |
| 76 | ssize_t read_bytes = readlink("/proc/self/exe", buf, sizeof(buf)); |
| 77 | bool failed = (read_bytes == -1); |
| 78 | #endif |
| 79 | if (failed) { |
| 80 | return ""; |
| 81 | } |
| 82 | buf[read_bytes] = '\0'; |
| 83 | return {buf}; |
| 84 | } |
| 85 | |
| 86 | std::string dirFromFullPath(const std::string &path) { |
| 87 | const auto pos = path.rfind(kPathSeparator); |
no outgoing calls
no test coverage detected