summarylogtreecommitdiffstats
path: root/dlopen.c
blob: 0cc81f9a005dcf2477f489a4c57c2d7dbc1d5f35 (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
29
#include <dlfcn.h>
#include <stdio.h>
#include <limits.h>
#include <sys/stat.h>

/* Simple program to see if dlopen() would succeed. */
int main(int argc, char **argv)
{
	int i;
	struct stat st;
	char buf[PATH_MAX];

	for (i=1; i<argc; i++) {
		if (dlopen(argv[i], RTLD_NOW)) {
			fprintf(stdout, "dlopen() of '%s' succeeded.\n", argv[i]);
			}
		else {
			snprintf(buf, sizeof (buf), "./%s", argv[i]);
			if ((!stat(buf, &st)) && dlopen(buf, RTLD_NOW)) {
				fprintf(stdout, "dlopen() of './%s' succeeded.\n", argv[i]);
				}
			else {
				fprintf(stdout, "dlopen() of '%s' failed: %s\n", argv[i], dlerror());
				return 1;
				}
			}
		}
	return 0;
}