1 #include <dlfcn.h>
2 #include <error.h>
3 #include <mcheck.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 
7 int
main(void)8 main (void)
9 {
10   void *su[5];
11   void *h;
12   int n;
13 
14   mtrace ();
15 
16   if ((su[0] = dlopen ("testobj1.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
17       || (su[1] = dlopen ("testobj2.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
18       || (su[2] = dlopen ("testobj3.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
19       || (su[3] = dlopen ("testobj4.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
20       || (su[4] = dlopen ("testobj5.so", RTLD_GLOBAL | RTLD_NOW)) == NULL)
21     error (EXIT_FAILURE, 0, "failed to load shared object: %s", dlerror ());
22 
23   h = dlopen ("failobj.so", RTLD_GLOBAL | RTLD_NOW);
24 
25   printf ("h = %p, %s\n", h, h == NULL ? "ok" : "fail");
26 
27   for (n = 0; n < 5; ++n)
28     if (dlclose (su[n]) != 0)
29       {
30 	printf ("failed to unload su[%d]: %s\n", n, dlerror ());
31 	exit (EXIT_FAILURE);
32       }
33 
34   return h != NULL;
35 }
36 
37 extern int foo (int a);
38 int
foo(int a)39 foo (int a)
40 {
41   return 10;
42 }
43