From 3f071a90a4313749b348a7d98284c005e5d87537 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 24 Mar 2018 08:25:58 -0700 Subject: Use proc_pidpath to get the process path on macOS when available --- Alc/helpers.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Alc/helpers.c') diff --git a/Alc/helpers.c b/Alc/helpers.c index e5545492..f7adfba0 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -39,6 +39,9 @@ #ifdef HAVE_DIRENT_H #include #endif +#ifdef HAVE_PROC_PIDPATH +#include +#endif #ifdef __FreeBSD__ #include @@ -754,6 +757,27 @@ void GetProcBinary(al_string *path, al_string *fname) sysctl(mib, 3, (void*)pathname, &pathlen, NULL, 0); pathname[pathlen] = 0; } +#endif +#ifdef HAVE_PROC_PIDPATH + if(!pathname) + { + const pid_t pid = getpid(); + char procpath[PROC_PIDPATHINFO_MAXSIZE]; + int ret; + + ret = proc_pidpath(pid, procpath, sizeof(procpath)); + if(ret < 1) + { + WARN("proc_pidpath(%d, ...) failed: %s\n", pid, strerror(errno)); + free(pathname); + pathname = NULL; + } + else + { + pathlen = strlen(procpath); + pathname = strdup(procpath); + } + } #endif if(!pathname) { -- cgit v1.2.3