blob: ef970bcf4f00731f3662ce4fc958764c1bc47804 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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;
}
|