From 4249f4666cb70fd8f013c3d8b03fc5275e7f8724 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 31 Jan 2016 21:11:15 -0800 Subject: [PATCH] David Carlier implemented SDL_GetBasePath() for OpenBSD --- src/filesystem/unix/SDL_sysfilesystem.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/filesystem/unix/SDL_sysfilesystem.c b/src/filesystem/unix/SDL_sysfilesystem.c index fa034a4565558..bd2e84cd1c5de 100644 --- a/src/filesystem/unix/SDL_sysfilesystem.c +++ b/src/filesystem/unix/SDL_sysfilesystem.c @@ -33,7 +33,7 @@ #include #include -#ifdef __FREEBSD__ +#if defined(__FREEBSD__) || defined(__OPENBSD__) #include #endif @@ -90,7 +90,26 @@ SDL_GetBasePath(void) return NULL; } } -#elif defined(__SOLARIS__) +#endif +#if defined(__OPENBSD__) + char **retvalargs; + size_t len; + const int mib[] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV }; + if (sysctl(mib, 4, NULL, &len, NULL, 0) != -1) { + retvalargs = SDL_malloc(len); + if (!retvalargs) { + SDL_OutOfMemory(); + return NULL; + } + sysctl(mib, 4, retvalargs, &len, NULL, 0); + retval = SDL_malloc(PATH_MAX + 1); + if (retval) + realpath(retvalargs[0], retval); + + SDL_free(retvalargs); + } +#endif +#if defined(__SOLARIS__) const char *path = getexecname(); if ((path != NULL) && (path[0] == '/')) { /* must be absolute path... */ retval = SDL_strdup(path);