diff options
author | Daniel Mack <zonque@gmail.com> | 2011-04-15 19:35:25 +0200 |
---|---|---|
committer | Colin Guthrie <colin@mageia.org> | 2011-04-23 18:23:37 +0100 |
commit | 7a3b3a376308df191b19b73fe8dbe97659a1061a (patch) | |
tree | c2c7ca1152e01201422e413b81164d909c773393 /src | |
parent | 2a44304bee40135a9a90b9af176729f895b0d5e8 (diff) |
util: Implement pa_get_binary_name() for Mac OS X
Diffstat (limited to 'src')
-rw-r--r-- | src/pulse/util.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/pulse/util.c b/src/pulse/util.c index c5cfc8ca..48ccf295 100644 --- a/src/pulse/util.c +++ b/src/pulse/util.c @@ -49,6 +49,11 @@ #include <sys/prctl.h> #endif +#ifdef OS_IS_DARWIN +#include <libgen.h> +#include <sys/sysctl.h> +#endif + #include <pulse/xmalloc.h> #include <pulse/timeval.h> @@ -221,6 +226,27 @@ char *pa_get_binary_name(char *s, size_t l) { } #endif +#ifdef OS_IS_DARWIN + { + int mib[] = { CTL_KERN, KERN_PROCARGS, getpid(), 0 }; + size_t len, nmib = (sizeof(mib) / sizeof(mib[0])) - 1; + char *buf; + + sysctl(mib, nmib, NULL, &len, NULL, 0); + buf = (char *) pa_xmalloc(len); + + if (sysctl(mib, nmib, buf, &len, NULL, 0) == 0) { + pa_strlcpy(s, basename(buf), l); + pa_xfree(buf); + return s; + } + + pa_xfree(buf); + + /* fall thru */ + } +#endif /* OS_IS_DARWIN */ + errno = ENOENT; return NULL; } |