aboutsummaryrefslogtreecommitdiffstats
path: root/src/sysdeps
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2025-04-02 06:02:35 +0000
committerLaurent Bercot <ska@appnovation.com>2025-04-02 06:02:35 +0000
commit200a70765a503fc94b546e5a52fdd90a59eee3b3 (patch)
tree343e317b83e45454239cdb50a50b3649bcdc174f /src/sysdeps
parent56ab53289c60c6fbb06f8d548d353535d5ed1140 (diff)
downloadskalibs-200a70765a503fc94b546e5a52fdd90a59eee3b3.tar.gz
Add sagetexecname() and all the necessary infrastructure
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/sysdeps')
-rw-r--r--src/sysdeps/try_nsgetexecutablepath.c14
-rw-r--r--src/sysdeps/trygetauxval.c12
-rw-r--r--src/sysdeps/trygetexecname.c11
-rw-r--r--src/sysdeps/trykernprocpathname.c18
-rw-r--r--src/sysdeps/tryprocselfexe.c13
5 files changed, 68 insertions, 0 deletions
diff --git a/src/sysdeps/try_nsgetexecutablepath.c b/src/sysdeps/try_nsgetexecutablepath.c
new file mode 100644
index 0000000..e2599cc
--- /dev/null
+++ b/src/sysdeps/try_nsgetexecutablepath.c
@@ -0,0 +1,14 @@
+/* ISC license. */
+
+#undef _POSIX_C_SOURCE
+#undef _XOPEN_SOURCE
+
+#include <stdint.h>
+#include <mach-o/dyld.h>
+
+int main (void)
+{
+ char buf[1024] ;
+ uint32_t len = sizeof(buf) ;
+ return _NSGetExecutablePath(buf, &len) >= 0 ;
+}
diff --git a/src/sysdeps/trygetauxval.c b/src/sysdeps/trygetauxval.c
new file mode 100644
index 0000000..cbf3da4
--- /dev/null
+++ b/src/sysdeps/trygetauxval.c
@@ -0,0 +1,12 @@
+/* ISC license. */
+
+#undef _POSIX_C_SOURCE
+#undef _XOPEN_SOURCE
+
+#include <sys/auxv.h>
+
+int main (void)
+{
+ unsigned long x = getauxval(AT_EXECFN) ;
+ return 0 ;
+}
diff --git a/src/sysdeps/trygetexecname.c b/src/sysdeps/trygetexecname.c
new file mode 100644
index 0000000..ac65071
--- /dev/null
+++ b/src/sysdeps/trygetexecname.c
@@ -0,0 +1,11 @@
+/* ISC license. */
+
+#undef _POSIX_C_SOURCE
+#undef _XOPEN_SOURCE
+
+#include <stdlib.h>
+
+int main (void)
+{
+ return !!getexecname() ;
+}
diff --git a/src/sysdeps/trykernprocpathname.c b/src/sysdeps/trykernprocpathname.c
new file mode 100644
index 0000000..b8e2867
--- /dev/null
+++ b/src/sysdeps/trykernprocpathname.c
@@ -0,0 +1,18 @@
+/* ISC license. */
+
+#undef _POSIX_C_SOURCE
+#undef _XOPEN_SOURCE
+
+#include <sys/types.h>
+#ifdef __NetBSD__
+#include <sys/param.h>
+#endif
+#include <sys/sysctl.h>
+
+int main (void)
+{
+ int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 } ;
+ char buf[1024] ;
+ size_t len = sizeof(buf) ;
+ return sysctl(mib, 4, buf, &len, 0, 0) >= 0 ;
+}
diff --git a/src/sysdeps/tryprocselfexe.c b/src/sysdeps/tryprocselfexe.c
new file mode 100644
index 0000000..e8b8a88
--- /dev/null
+++ b/src/sysdeps/tryprocselfexe.c
@@ -0,0 +1,13 @@
+/* ISC license */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+
+int main (int argc, char const *const *argv)
+{
+ char buf[8192] ;
+ if (argc < 2) return 111 ;
+ ssize_t r = readlink(argv[1], buf, 8192) ;
+ return r == -1 ? errno == EIO || errno == ELOOP ? 111 : 1 : r <= 1 ;
+}