Hi,
same as earlier but for FreeBSD this time.
Thanks.
From 07be546638949864ef678b0e39871b7febceeaed Mon Sep 17 00:00:00 2001
From: DC
Date: Tue, 17 Aug 2021 12:55:49 +0100
Subject: [PATCH] BUILD: tools: get the absolute path of the current binary on
FreeBSD. FreeBSD stores the absolute path into the auxiliary vector as well.
---
src/tools.c | 14 ++
1 file changed, 14 insertions(+)
diff --git a/src/tools.c b/src/tools.c
index 545fd9e8d..1961689dd 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -16,6 +16,12 @@
#include
#endif
+#if defined(__FreeBSD__)
+#include
+#include
+extern void *__elf_aux_vector;
+#endif
+
#if defined(__NetBSD__)
#include
#include
@@ -4766,6 +4772,14 @@ const char *get_exec_path()
if (execfn && execfn != ENOENT)
ret = (const char *)execfn;
+#elif defined(__FreeBSD__)
+ Elf_Auxinfo *auxv;
+ for (auxv = __elf_aux_vector; auxv->a_type != AT_NULL; ++auxv) {
+ if (auxv->a_type == AT_EXECPATH) {
+ ret = (const char *)auxv->a_un.a_ptr;
+ break;
+ }
+ }
#elif defined(__NetBSD__)
AuxInfo *auxv;
for (auxv = _dlauxinfo(); auxv->a_type != AT_NULL; ++auxv) {
--
2.32.0