MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ddio_GetBinaryPath

Function ddio_GetBinaryPath

ddio/lnxio.cpp:109–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109bool 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}

Callers 1

InitIOSystemsFunction · 0.85

Calls 1

ErrorFunction · 0.85

Tested by

no test coverage detected