From: cloudwalk Date: Tue, 26 May 2020 14:17:44 +0000 (+0000) Subject: Fix getting exe name on FreeBSD, which hasn't used /proc for quite a while now X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2ee589f9508dae34026d932a5140717fe6b834cc;p=xonotic%2Fdarkplaces.git Fix getting exe name on FreeBSD, which hasn't used /proc for quite a while now From https://gitlab.com/xonotic/darkplaces/-/merge_requests/54 git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12587 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/sys_shared.c b/sys_shared.c index 5171b34e..0db4c034 100644 --- a/sys_shared.c +++ b/sys_shared.c @@ -18,6 +18,9 @@ #pragma comment(lib, "winmm.lib") #endif #else +# ifdef __FreeBSD__ +# include +# endif # include # include # include @@ -498,7 +501,12 @@ 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); + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; + size_t exenamebuflen = sizeof(exenamebuf)-1; + if (sysctl(mib, 4, exenamebuf, &exenamebuflen, NULL, 0) == 0) + { + n = exenamebuflen; + } #elif defined(__linux__) n = readlink("/proc/self/exe", exenamebuf, sizeof(exenamebuf)-1); #endif