$OpenBSD: patch-src_pulse_util_c,v 1.10 2019/09/16 06:04:27 ajacoutot Exp $

Implement pa_get_binary_name().

Index: src/pulse/util.c
--- src/pulse/util.c.orig
+++ src/pulse/util.c
@@ -52,6 +52,11 @@
 #include <sys/sysctl.h>
 #endif
 
+#ifdef __OpenBSD__
+#include <libgen.h>
+#include <sys/sysctl.h>
+#endif
+
 #include <pulse/xmalloc.h>
 #include <pulse/timeval.h>
 
@@ -248,6 +253,30 @@ char *pa_get_binary_name(char *s, size_t l) {
         }
     }
 #endif
+
+#ifdef __OpenBSD__
+    {
+        size_t len;
+        char **buf;
+
+        int mib[] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV };
+
+        if (sysctl (mib, 4, NULL, &len, NULL, 0) == -1)
+            return NULL;
+
+        buf = (char *) pa_xmalloc(len);
+
+        if (sysctl(mib, 4, buf, &len, NULL, 0) == 0) {
+            pa_strlcpy(s, basename(*buf), l);
+            pa_xfree(buf);
+            return s;
+        }
+
+        pa_xfree(buf);
+
+        /* fall thru */
+    }
+#endif /* __OpenBSD__ */
 
 #if defined(HAVE_DLADDR) && defined(PA_GCC_WEAKREF)
     {
