Back to index

glibc  2.9
unload5.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   dlopen ("unload3mod4.so", RTLD_GLOBAL | RTLD_NOW);
00015   dlclose (h);
00016   dlclose (g);
00017 
00018   g = dlopen ("unload3mod3.so", RTLD_GLOBAL | RTLD_NOW);
00019   h = dlopen ("unload3mod4.so", RTLD_GLOBAL | RTLD_NOW);
00020   if (g == NULL || h == NULL)
00021     {
00022       printf ("dlopen unload3mod{3,4}.so failed: %p %p\n", g, h);
00023       return 1;
00024     }
00025 
00026   int (*fn) (int);
00027   fn = dlsym (h, "bar");
00028   if (fn == NULL)
00029     {
00030       puts ("dlsym failed");
00031       return 1;
00032     }
00033 
00034   int val = fn (16);
00035   if (val != 24)
00036     {
00037       printf ("bar returned %d != 24\n", val);
00038       return 1;
00039     }
00040 
00041   return 0;
00042 }