Implement getCurrentExecutableLocation() on FreeBSD (#3688)

This commit is contained in:
Kevin Zheng 2019-01-07 18:31:15 -06:00 committed by auria.mg
parent bec1c319f6
commit 75076106b9

View File

@ -34,6 +34,11 @@
# include <errno.h>
#endif
#ifdef __FreeBSD__
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
#ifdef ANDROID
#include <dlfcn.h>
#include <fstream>
@ -58,6 +63,15 @@ std::string SeparateProcess::getCurrentExecutableLocation()
return file_manager->getFileSystem()->getAbsolutePath(path).c_str();
}
return "";
#elif defined (__FreeBSD__)
char path[PATH_MAX];
size_t len = PATH_MAX;
const int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
if (sysctl(&mib[0], 4, &path, &len, NULL, 0) == 0)
{
return file_manager->getFileSystem()->getAbsolutePath(path).c_str();
}
return "";
#else
// Assume Linux
return file_manager->getFileSystem()->getAbsolutePath("/proc/self/exe")