summaryrefslogtreecommitdiffstats
path: root/polyp/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'polyp/util.c')
-rw-r--r--polyp/util.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/polyp/util.c b/polyp/util.c
index 45e1b605..1dbb8697 100644
--- a/polyp/util.c
+++ b/polyp/util.c
@@ -39,6 +39,7 @@
#include <sys/time.h>
#include <sched.h>
#include <sys/resource.h>
+#include <limits.h>
#include "util.h"
#include "xmalloc.h"
@@ -322,3 +323,27 @@ int pa_fd_set_cloexec(int fd, int b) {
return 0;
}
+
+char *pa_get_binary_name(char *s, size_t l) {
+ char path[PATH_MAX];
+ int i;
+ assert(s && l);
+
+ /* This works on Linux only */
+
+ snprintf(path, sizeof(path), "/proc/%u/exe", (unsigned) getpid());
+ if ((i = readlink(path, s, l-1)) < 0)
+ return NULL;
+
+ s[i] = 0;
+ return s;
+}
+
+char *pa_path_get_filename(const char *p) {
+ char *fn;
+
+ if ((fn = strrchr(p, '/')))
+ return fn+1;
+
+ return (char*) p;
+}