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