[SDL] SDL_GetBasePath / OpenBSD

David CARLIER devnexen at gmail.com
Sat Jan 23 08:12:26 PST 2016


Hi all,

For my first submission I wanted to implement SDL_GetBasePath for OpenBSD.

Hope it is helpful.

Kind regards.
-------------- next part --------------
diff -r 4f139e059592 src/filesystem/unix/SDL_sysfilesystem.c
--- a/src/filesystem/unix/SDL_sysfilesystem.c	Fri Jan 22 13:12:16 2016 -0800
+++ b/src/filesystem/unix/SDL_sysfilesystem.c	Sat Jan 23 16:07:21 2016 +0000
@@ -33,7 +33,7 @@
 #include <sys/types.h>
 #include <limits.h>
 
-#ifdef __FREEBSD__
+#if defined(__FREEBSD__) || defined(__OPENBSD__)
 #include <sys/sysctl.h>
 #endif
 
@@ -90,7 +90,26 @@
             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);


More information about the SDL mailing list