From 063467ff8158361233b45fae3247d9a49bff146d Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Sun, 20 Feb 2022 16:28:58 +0000 Subject: [PATCH] Sys_FindExecutableName FreeBSD fix. Retrieving the path via native API rather than the optional presence of the procfs support. --- sys_shared.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sys_shared.c b/sys_shared.c index f1c0d60c..b8b26917 100644 --- a/sys_shared.c +++ b/sys_shared.c @@ -24,6 +24,9 @@ # ifdef SUPPORTDLL # include # endif +# ifdef __FreeBSD__ +# include +# 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 -- 2.39.2