| 107 | } |
| 108 | |
| 109 | bool ddio_GetBinaryPath(char *exec_path, size_t len) { |
| 110 | #ifdef MACOSX |
| 111 | if (exec_path == NULL || len == 0) { |
| 112 | fprintf(stderr, "Invalid arguments\n"); |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | uint32_t size = (uint32_t)len; |
| 117 | if (_NSGetExecutablePath(exec_path, &size) != 0) { |
| 118 | fprintf(stderr, "Buffer too small; need size %u\n", size); |
| 119 | return false; |
| 120 | } |
| 121 | #elif defined(__LINUX__) |
| 122 | if (realpath("/proc/self/exe", exec_path) == NULL) { |
| 123 | perror("realpath"); |
| 124 | return false; |
| 125 | } |
| 126 | #else |
| 127 | if (GetModuleFileName(NULL, exec_path, len) == 0) { |
| 128 | DWORD error = GetLastError(); |
| 129 | Error("GetModuleFileName failed!"); |
| 130 | return false; |
| 131 | } |
| 132 | exec_path[len - 1] = '\0'; |
| 133 | return true; |
| 134 | |
| 135 | #endif |
| 136 | exec_path[len - 1] = '\0'; |
| 137 | return true; |
| 138 | } |
no test coverage detected