Back to index

glibc  2.9
unload3.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <stdio.h>
00003 
00004 int
00005 main (void)
00006 {
00007   void *g = dlopen ("unload3mod1.so", RTLD_GLOBAL | RTLD_NOW);
00008   void *h = dlopen ("unload3mod2.so", RTLD_GLOBAL | RTLD_NOW);
00009   if (g == NULL || h == NULL)
00010     {
00011       printf ("dlopen unload3mod{1,2}.so failed: %p %p\n", g, h);
00012       return 1;
00013     }
00014   dlclose (h);
00015   dlclose (g);
00016 
00017   g = dlopen ("unload3mod3.so", RTLD_GLOBAL | RTLD_NOW);
00018   h = dlopen ("unload3mod4.so", RTLD_GLOBAL | RTLD_NOW);
00019   if (g == NULL || h == NULL)
00020     {
00021       printf ("dlopen unload3mod{3,4}.so failed: %p %p\n", g, h);
00022       return 1;
00023     }
00024 
00025   int (*fn) (int);
00026   fn = dlsym (h, "bar");
00027   if (fn == NULL)
00028     {
00029       puts ("dlsym failed");
00030       return 1;
00031     }
00032 
00033   int val = fn (16);
00034   if (val != 24)
00035     {
00036       printf ("bar returned %d != 24\n", val);
00037       return 1;
00038     }
00039 
00040   return 0;
00041 }