xref: /openbsd-src/regress/libexec/ld.so/lazy/prog/prog.c (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1 /*	$OpenBSD: prog.c,v 1.1.1.1 2008/01/02 18:36:59 matthieu Exp $ */
2 /* Public Domain, 2008, Matthieu Herrb */
3 
4 #include <dlfcn.h>
5 #include <stdio.h>
6 
7 void *handle = NULL;
8 
9 typedef int (*foofunc)(void);
10 
11 int
12 main(int argc, char *argv[])
13 {
14 	foofunc foo;
15 	int i;
16 
17 	printf("loading: %s\n", FOO);
18 	handle = dlopen(FOO, RTLD_LAZY|RTLD_GLOBAL);
19 	if (handle == NULL) {
20 		errx(1, "dlopen: %s: %s\n", FOO, dlerror());
21 	}
22 	printf("loaded: %s\n", FOO);
23 	printf("looking up foo\n");
24 	foo = (foofunc)dlsym(handle, "foo");
25 	printf("found %p - calling it\n", foo);
26 	i = foo();
27 	printf("done.\n");
28 	exit(i);
29 }
30