diff options
author | kcat <[email protected]> | 2017-06-09 12:14:56 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2017-06-09 12:14:56 -0700 |
commit | ba0644254c9cbf0fac21af49cbafd5289c90ff1c (patch) | |
tree | 1ab89d8abc6b3f671c4445e23f4be030abca4774 /Alc | |
parent | b4aea294c3eaf592fb392c12976c592c233a3a2b (diff) | |
parent | 39e4756b376225e35b7e082be70797ec27a42cdd (diff) |
Merge pull request #123 from rdb/master
Implement GetProcPath for FreeBSD
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/helpers.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Alc/helpers.c b/Alc/helpers.c index 8e685c75..f1cd1f66 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -40,6 +40,10 @@ #include <dirent.h> #endif +#ifdef __FreeBSD__ +#include <sys/sysctl.h> +#endif + #ifndef AL_NO_UID_DEFS #if defined(HAVE_GUIDDEF_H) || defined(HAVE_INITGUID_H) #define INITGUID @@ -707,9 +711,22 @@ void UnmapFileMem(const struct FileMapping *mapping) al_string GetProcPath(void) { al_string ret = AL_STRING_INIT_STATIC(); - const char *fname; char *pathname, *sep; size_t pathlen; + +#ifdef __FreeBSD__ + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; + mib[3] = getpid(); + if (sysctl(mib, 4, NULL, &pathlen, NULL, 0) == -1) { + WARN("Failed to sysctl kern.proc.pathname.%d: %s\n", mib[3], strerror(errno)); + return ret; + } + + pathname = malloc(pathlen + 1); + sysctl(mib, 4, (void*)pathname, &pathlen, NULL, 0); + pathname[pathlen] = 0; +#else + const char *fname; ssize_t len; pathlen = 256; @@ -738,6 +755,8 @@ al_string GetProcPath(void) } pathname[len] = 0; +#endif + sep = strrchr(pathname, '/'); if(sep) alstr_copy_range(&ret, pathname, sep); |