Back to index

glibc  2.9
loadfail.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <error.h>
00003 #include <mcheck.h>
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 
00007 int
00008 main (void)
00009 {
00010   void *su[5];
00011   void *h;
00012   int n;
00013 
00014   mtrace ();
00015 
00016   if ((su[0] = dlopen ("testobj1.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
00017       || (su[1] = dlopen ("testobj2.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
00018       || (su[2] = dlopen ("testobj3.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
00019       || (su[3] = dlopen ("testobj4.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
00020       || (su[4] = dlopen ("testobj5.so", RTLD_GLOBAL | RTLD_NOW)) == NULL)
00021     error (EXIT_FAILURE, 0, "failed to load shared object: %s", dlerror ());
00022 
00023   h = dlopen ("failobj.so", RTLD_GLOBAL | RTLD_NOW);
00024 
00025   printf ("h = %p, %s\n", h, h == NULL ? "ok" : "fail");
00026 
00027   for (n = 0; n < 5; ++n)
00028     if (dlclose (su[n]) != 0)
00029       {
00030        printf ("failed to unload su[%d]: %s\n", n, dlerror ());
00031        exit (EXIT_FAILURE);
00032       }
00033 
00034   return h != NULL;
00035 }
00036 
00037 extern int foo (int a);
00038 int
00039 foo (int a)
00040 {
00041   return 10;
00042 }