| 201 | } |
| 202 | |
| 203 | fs::path getProgramPath() |
| 204 | { |
| 205 | // /* |
| 206 | // * Returns the relative path to the executable file (including symlinks). |
| 207 | // * |
| 208 | // * To resolve symlinks, wrap this call in getAbsolutePath(). |
| 209 | // */ |
| 210 | char executableRelativePath[1024] = {'\0'}; |
| 211 | |
| 212 | #ifdef __APPLE__ |
| 213 | uint32_t pathSize = sizeof(executableRelativePath); |
| 214 | _NSGetExecutablePath(executableRelativePath, &pathSize); |
| 215 | #elif __linux__ |
| 216 | ssize_t len = readlink("/proc/self/exe", executableRelativePath, sizeof(executableRelativePath) - 1); |
| 217 | if (len == -1) { |
| 218 | std::cout << "ERROR: Unable to locate executable." << std::endl; |
| 219 | std::exit(EXIT_FAILURE); |
| 220 | } else { |
| 221 | executableRelativePath[len] = '\0'; |
| 222 | } |
| 223 | #elif _WIN32 |
| 224 | GetModuleFileName(NULL, executableRelativePath, sizeof(executableRelativePath)); |
| 225 | #endif |
| 226 | |
| 227 | return executableRelativePath; |
| 228 | } |
| 229 | |
| 230 | // TODO: remove? seems like fs::path::extension would do fine. It's only used in CommandLineInterface to check the input file type, so we could |
| 231 | // just compare to ".EPJSON" instead of "EPJSON"... |
no outgoing calls
no test coverage detected