]> code.delx.au - pulseaudio/commitdiff
util: Implement pa_get_binary_name() for Mac OS X
authorDaniel Mack <zonque@gmail.com>
Fri, 15 Apr 2011 17:35:25 +0000 (19:35 +0200)
committerColin Guthrie <colin@mageia.org>
Sat, 23 Apr 2011 17:23:37 +0000 (18:23 +0100)
src/pulse/util.c

index c5cfc8cad91b30171437f41fd65343f9b2628ffd..48ccf2951beef152bacb3b507f03613e20e1bfe0 100644 (file)
 #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;
 }