From a2e4641865f5b1478c4243767abd208772a303b3 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 1 Mar 2017 01:16:01 +0100 Subject: make: support freebsd properly. drop solaris --- src/blogc-make/exec.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/blogc-make/exec.c b/src/blogc-make/exec.c index de37536..2fc46d8 100644 --- a/src/blogc-make/exec.c +++ b/src/blogc-make/exec.c @@ -14,6 +14,13 @@ #include #include #include + +#ifdef __FreeBSD__ +#include +#include +#include +#endif + #include "../common/error.h" #include "../common/file.h" #include "../common/utils.h" @@ -33,12 +40,24 @@ bm_exec_find_binary(const char *bin, const char *env) // second try: same dir as current exec char *path = realpath("/proc/self/exe", NULL); // Linux +#ifdef __FreeBSD__ if (path == NULL) { - path = realpath("/proc/curproc/file", NULL); // FreeBSD + path = realpath("/proc/curproc/file", NULL); // FreeBSD with /proc if (path == NULL) { - path = realpath("/proc/self/path/a.out", NULL); // Solaris + // FreeBSD without /proc (default for 11.0) + int name[4]; + name[0] = CTL_KERN; + name[1] = KERN_PROC; + name[2] = KERN_PROC_PATHNAME; + name[3] = -1; + char buf[PATH_MAX]; + size_t buf_len = sizeof(buf); + if (-1 != sysctl(name, 4, buf, &buf_len, NULL, 0)) { + path = bc_strdup_printf("%.*s", buf_len, buf); + } } } +#endif if (path != NULL) { char *dir = bc_strdup(dirname(path)); free(path); -- cgit v1.2.3-18-g5258