Back to index

glibc  2.9
unload4.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <stdio.h>
00003 #include <malloc.h>
00004 
00005 int
00006 main (void)
00007 {
00008 #ifdef M_PERTURB
00009   mallopt (M_PERTURB, 0xaa);
00010 #endif
00011 
00012   void *h;
00013   int (*fn) (int);
00014   h = dlopen ("unload4mod1.so", RTLD_LAZY);
00015   if (h == NULL)
00016     {
00017       puts ("1st dlopen failed");
00018       return 1;
00019     }
00020   fn = dlsym (h, "foo");
00021   if (fn == NULL)
00022     {
00023       puts ("dlsym failed");
00024       return 1;
00025     }
00026   int n = fn (10);
00027   if (n != 28)
00028     {
00029       printf ("foo (10) returned %d != 28\n", n);
00030       return 1;
00031     }
00032   dlclose (h);
00033   h = dlopen ("unload4mod3.so", RTLD_LAZY);
00034   fn = dlsym (h, "mod3fn2");
00035   if (fn == NULL)
00036     {
00037       puts ("second dlsym failed");
00038       return 1;
00039     }
00040   n = fn (10);
00041   if (n != 22)
00042     {
00043       printf ("mod3fn2 (10) returned %d != 22\n", n);
00044       return 1;
00045     }
00046   dlclose (h);
00047   return 0;
00048 }