aboutsummaryrefslogtreecommitdiff
path: root/tests/relocatability-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/relocatability-test.c')
-rw-r--r--tests/relocatability-test.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/relocatability-test.c b/tests/relocatability-test.c
new file mode 100644
index 0000000..ef970bc
--- /dev/null
+++ b/tests/relocatability-test.c
@@ -0,0 +1,28 @@
+/*
+ * This prints the location of the current binary as
+ * reported by the dynamic linker.
+ * It does not work on all UNIX-like platforms.
+ * For instance, it doesn't on Linux.
+ *
+ * Link with: cc -o relocatability-test relocatability-test.c -ldl
+ */
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <dlfcn.h>
+
+int
+main(int argc, char **argv)
+{
+ Dl_info info;
+
+ printf("argv[0] = %s\n", argv[0]);
+
+ if (!dladdr(main, &info)) {
+ fprintf(stderr, "Cannot query executable's path: %s\n",
+ dlerror());
+ return 1;
+ }
+
+ printf("dli_fname = %s\n", info.dli_fname);
+ return 0;
+}