/** * Get the location of the executable * @return the location of the executable, as a string. */ const char *GetExecutableLocation() { const char *path; char buf[1024]; #if defined (WIN32) || defined (WIN64) GetModuleFileName(path, &size); #elif defined (__APPLE__) _NSGetExecutablePath(path, &size); #elif defined(UNIX) if (readlink("/proc/self/exe", buf, sizeof(buf)) == -1) path = buf; #elif defined(__FreeBSD__) int mib[4]; mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_PATHNAME; mib[3] = -1; sysctl(mib, 4, buf, sizeof(buf), NULL, 0); path = buf; #elif defined(SUNOS) path = getexecname(); #endif return path; }