Implement File::GetExePath() for FreeBSD
This commit is contained in:
parent
0c14b0c8a7
commit
3ca50f7879
|
@ -60,6 +60,10 @@
|
||||||
#include "jni/AndroidCommon/AndroidCommon.h"
|
#include "jni/AndroidCommon/AndroidCommon.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(__FreeBSD__)
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
namespace File
|
namespace File
|
||||||
|
@ -738,6 +742,15 @@ std::string GetExePath()
|
||||||
return PathToString(exe_path_absolute);
|
return PathToString(exe_path_absolute);
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
return GetBundleDirectory();
|
return GetBundleDirectory();
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
|
int name[4]{CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
|
||||||
|
size_t length = 0;
|
||||||
|
if (sysctl(name, 4, nullptr, &length, nullptr, 0) != 0 || length == 0)
|
||||||
|
return {};
|
||||||
|
std::string dolphin_exe_path(length, '\0');
|
||||||
|
if (sysctl(name, 4, dolphin_exe_path.data(), &length, nullptr, 0) != 0)
|
||||||
|
return {};
|
||||||
|
return dolphin_exe_path;
|
||||||
#else
|
#else
|
||||||
char dolphin_exe_path[PATH_MAX];
|
char dolphin_exe_path[PATH_MAX];
|
||||||
ssize_t len = ::readlink("/proc/self/exe", dolphin_exe_path, sizeof(dolphin_exe_path));
|
ssize_t len = ::readlink("/proc/self/exe", dolphin_exe_path, sizeof(dolphin_exe_path));
|
||||||
|
|
Loading…
Reference in New Issue