#include <sys/types.h>
#include <sys/stat.h>
+#if defined(__FreeBSD__)
+#include <sys/sysctl.h>
+#endif
#include <fcntl.h>
#include <unistd.h>
zend_elf_header hdr;
zend_elf_sectheader sect;
int i;
+#if defined(__linux__)
int fd = open("/proc/self/exe", O_RDONLY);
+#elif defined(__NetBSD__)
+ int fd = open("/proc/curproc/exe", O_RDONLY);
+#elif defined(__FreeBSD__)
+ char path[PATH_MAX];
+ size_t pathlen = sizeof(path);
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
+ if (sysctl(mib, 4, path, &pathlen, NULL, 0) == -1) {
+ return;
+ }
+ int fd = open(path, O_RDONLY);
+#else
+ // To complete eventually for other ELF platforms.
+ // Otherwise APPLE is Mach-O
+ int fd = -1;
+#endif
if (fd >= 0) {
if (read(fd, &hdr, sizeof(hdr)) == sizeof(hdr)
# include <pthread.h>
#elif defined(__FreeBSD__)
# include <sys/thr.h>
+# include <sys/sysctl.h>
#elif defined(__NetBSD__)
# include <lwp.h>
#endif
return;
}
+#if defined(__linux__)
fd = open("/proc/self/exe", O_RDONLY);
+#elif defined(__NetBSD__)
+ int fd = open("/proc/curproc/exe", O_RDONLY);
+#elif defined(__FreeBSD__)
+ char path[PATH_MAX];
+ size_t pathlen = sizeof(path);
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
+ if (sysctl(mib, 4, path, &pathlen, NULL, 0) == -1) {
+ return;
+ }
+ fd = open(path, O_RDONLY);
+#else
+ fd = -1;
+#endif
if (fd < 0) {
return;
}