Implement getPath on BSDs --- shared/offline_compiler/source/utilities/linux/get_path.cpp.orig 2020-02-28 16:16:42 UTC +++ shared/offline_compiler/source/utilities/linux/get_path.cpp @@ -10,11 +10,33 @@ #include #include +#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) +#include +#endif + std::string getPath() { +#if defined(KERN_PROC_PATHNAME) + char exepath[PATH_MAX + 1] = {0}; + size_t len = sizeof(exepath); + int mib[] = { + CTL_KERN, +#if defined(__NetBSD__) + KERN_PROC_ARGS, + -1, + KERN_PROC_PATHNAME, +#else + KERN_PROC, + KERN_PROC_PATHNAME, + -1, +#endif + }; + if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), exepath, &len, NULL, 0) != -1) { +#else // Linux char exepath[128] = {0}; std::stringstream ss; ss << "/proc/" << getpid() << "/exe"; if (readlink(ss.str().c_str(), exepath, 128) != -1) { +#endif std::string path = std::string(exepath); path = path.substr(0, path.find_last_of('/') + 1); return path;