diff --git a/src/cli/cli.c b/src/cli/cli.c index 8010e2258..ed58059c2 100644 --- a/src/cli/cli.c +++ b/src/cli/cli.c @@ -107,6 +107,10 @@ static int cbm_powershell_quote_word(const char *value, char *out, size_t out_si #include #include // strtok_r #include // mode_t, S_IXUSR +#ifdef __FreeBSD__ +#include +#include +#endif #include #include #include // MAX_WBITS @@ -8913,6 +8917,13 @@ static bool cbm_detect_self_path(char *buf, size_t buf_sz, const char *home) { if (!exact) { buf[0] = '\0'; } +#elif defined(__FreeBSD__) + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; + size_t cb = buf_sz; + exact = sysctl(mib, 4, buf, &cb, NULL, 0) == 0 && cb > 0; + if (!exact) { + buf[0] = '\0'; + } #else ssize_t sp_len = readlink("/proc/self/exe", buf, buf_sz - SKIP_ONE); exact = sp_len > 0 && (size_t)sp_len < buf_sz - SKIP_ONE;