]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Sys_FindExecutableName FreeBSD fix. sys_freebsd_upd 128/head
authorDavid CARLIER <devnexen@gmail.com>
Sun, 20 Feb 2022 16:28:58 +0000 (16:28 +0000)
committerDavid CARLIER <devnexen@gmail.com>
Sun, 20 Feb 2022 16:28:58 +0000 (16:28 +0000)
Retrieving the path via native API rather than the optional presence
of the procfs support.

sys_shared.c

index f1c0d60c3324cf3c48ca39fbd939891d39adf95f..b8b26917537a8f27d374610f752d6d0cbe178d56 100644 (file)
@@ -24,6 +24,9 @@
 # ifdef SUPPORTDLL
 #  include <dlfcn.h>
 # endif
+# ifdef __FreeBSD__
+#  include <sys/sysctl.h>
+# endif
 #endif
 
 static char sys_timestring[128];
@@ -493,7 +496,10 @@ static const char *Sys_FindExecutableName(void)
        static char exenamebuf[MAX_OSPATH+1];
        ssize_t n = -1;
 #if defined(__FreeBSD__)
-       n = readlink("/proc/curproc/file", exenamebuf, sizeof(exenamebuf)-1);
+       size_t l = sizeof(exenamebuf);
+       int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
+       if (sysctl(mib, 4, exenamebuf, &l, NULL, 0) == 0)
+               n = (ssize_t)l;
 #elif defined(__linux__)
        n = readlink("/proc/self/exe", exenamebuf, sizeof(exenamebuf)-1);
 #endif