diff --git a/SDL/utils.c b/SDL/utils.c index d14beed..539e351 100644 --- a/SDL/utils.c +++ b/SDL/utils.c @@ -1,62 +1,24 @@ +#include #include #include -#ifdef __APPLE__ -#include -#endif -#ifdef _WIN32 -#include -#include -#endif -#ifdef __linux__ -#include -#include -#endif #include "utils.h" const char *executable_folder(void) { - static char path[1024] = {0,}; - if (path[0]) { - return path; - } - /* Ugly unportable code! :( */ -#ifdef __APPLE__ - unsigned int length = sizeof(path) - 1; - _NSGetExecutablePath(&path[0], &length); -#else -#ifdef __linux__ - ssize_t __attribute__((unused)) length = readlink("/proc/self/exe", &path[0], sizeof(path) - 1); - assert (length != -1); -#else -#ifdef _WIN32 - HMODULE hModule = GetModuleHandle(NULL); - GetModuleFileName(hModule, path, sizeof(path) - 1); -#else - /* No OS-specific way, assume running from CWD */ - getcwd(&path[0], sizeof(path) - 1); - return path; -#endif -#endif -#endif - size_t pos = strlen(path); - while (pos) { - pos--; -#ifdef _WIN32 - if (path[pos] == '\\') { -#else - if (path[pos] == '/') { -#endif - path[pos] = 0; - break; + static const char *ret = NULL; + if (!ret) { + ret = SDL_GetBasePath(); + if (!ret) { + ret = "./"; } } - return path; + return ret; } char *executable_relative_path(const char *filename) { static char path[1024]; - snprintf(path, sizeof(path), "%s/%s", executable_folder(), filename); + snprintf(path, sizeof(path), "%s%s", executable_folder(), filename); return path; }