| 182 | } |
| 183 | |
| 184 | std::string GetCurrentExecutablePath() |
| 185 | { |
| 186 | char exePath[PATH_MAX] = { 0 }; |
| 187 | #ifdef __linux__ |
| 188 | auto bytesRead = readlink("/proc/self/exe", exePath, sizeof(exePath)); |
| 189 | if (bytesRead == -1) |
| 190 | { |
| 191 | LOG_FATAL("failed to read /proc/self/exe"); |
| 192 | } |
| 193 | #elif defined(__HAIKU__) |
| 194 | image_info info; |
| 195 | int32 cookie = 0; |
| 196 | |
| 197 | while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) >= B_OK) |
| 198 | { |
| 199 | if (info.type == B_APP_IMAGE) |
| 200 | { |
| 201 | strlcpy(exePath, info.name, sizeof(exePath)); |
| 202 | break; |
| 203 | } |
| 204 | } |
| 205 | #elif defined(__FreeBSD__) || defined(__NetBSD__) |
| 206 | #if defined(__FreeBSD__) |
| 207 | const int32_t mib[] = { |
| 208 | CTL_KERN, |
| 209 | KERN_PROC, |
| 210 | KERN_PROC_PATHNAME, |
| 211 | -1, |
| 212 | }; |
| 213 | #else |
| 214 | const int32_t mib[] = { |
| 215 | CTL_KERN, |
| 216 | KERN_PROC_ARGS, |
| 217 | -1, |
| 218 | KERN_PROC_PATHNAME, |
| 219 | }; |
| 220 | #endif |
| 221 | auto exeLen = sizeof(exePath); |
| 222 | if (sysctl(mib, 4, exePath, &exeLen, nullptr, 0) == -1) |
| 223 | { |
| 224 | LOG_FATAL("failed to get process path"); |
| 225 | } |
| 226 | #elif defined(__OpenBSD__) |
| 227 | // There is no way to get the path name of a running executable. |
| 228 | // If you are not using the port or package, you may have to change this line! |
| 229 | strlcpy(exePath, "/usr/local/bin/", sizeof(exePath)); |
| 230 | #else |
| 231 | #error "Platform does not support full path exe retrieval" |
| 232 | #endif |
| 233 | return exePath; |
| 234 | } |
| 235 | |
| 236 | u8string StrDecompToPrecomp(u8string_view input) |
| 237 | { |
no outgoing calls
no test coverage detected