Skip to content

Commit 159c001

Browse files
Vanilla Hsusgolemon
Vanilla Hsu
authored andcommitted
support current_executable_path on FreeBSD
- add support for current_executable_path on FreeBSD Closes #878
1 parent 1845ed2 commit 159c001

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

hphp/util/current_executable.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#include <mach-o/dyld.h>
2323
#endif
2424

25+
#ifdef __FreeBSD__
26+
#include <sys/sysctl.h>
27+
#endif
28+
2529
namespace HPHP {
2630

2731
std::string current_executable_path() {
@@ -34,8 +38,22 @@ std::string current_executable_path() {
3438
uint32_t size = sizeof(result);
3539
uint32_t success = _NSGetExecutablePath(result, &size);
3640
return std::string(result, (success == 0) ? size : 0);
41+
#elif defined(__FreeBSD__)
42+
char result[PATH_MAX];
43+
size_t size = sizeof(result);
44+
int mib[4];
45+
46+
mib[0] = CTL_KERN;
47+
mib[1] = KERN_PROC;
48+
mib[2] = KERN_PROC_PATHNAME;
49+
mib[3] = -1;
50+
51+
if (sysctl(mib, 4, result, &size, nullptr, 0) < 0) {
52+
return std::string();
53+
}
54+
return std::string(result, (size > 0) ? size : 0);
3755
#else
38-
// Return empty string for all other platforms for now (e.g. FreeBSD)
56+
// XXX: How do you do this on your platform?
3957
return std::string();
4058
#endif
4159
}

0 commit comments

Comments
 (0)