Index: lib/Support/Unix/Path.inc =================================================================== --- lib/Support/Unix/Path.inc +++ lib/Support/Unix/Path.inc @@ -48,6 +48,9 @@ #ifdef __APPLE__ #include #endif +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) +#include +#endif // Both stdio.h and cstdio are included via different pathes and // stdcxx's cstdio doesn't include stdio.h, so it doesn't #undef the macros @@ -161,9 +164,19 @@ if (realpath(exe_path, link_path)) return link_path; } -#elif defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \ - defined(__OpenBSD__) || defined(__minix) || defined(__DragonFly__) || \ - defined(__FreeBSD_kernel__) +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ + defined(__NetBSD__) + char exe_path[MAXPATHLEN]; + size_t len = sizeof(exe_path); + int name[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME }; + + name[3] = getpid(); + if (sysctl(name, 4, exe_path, &len, NULL, 0) == 0) + return exe_path; + else if (argv0 != nullptr && getprogpath(exe_path, argv0) != nullptr) + return exe_path; +#elif defined(__Bitrig__) || defined(__OpenBSD__) || defined(__minix) || \ + defined(__DragonFly__) char exe_path[PATH_MAX]; if (getprogpath(exe_path, argv0) != NULL)