Back to index

glibc  2.9
defaultmod2.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <stdio.h>
00003 
00004 extern int found_in_mod1 (void);
00005 int
00006 found_in_mod1 (void)
00007 {
00008   return 1;
00009 }
00010 
00011 extern int found_in_mod2 (void);
00012 int
00013 found_in_mod2 (void)
00014 {
00015   return 2;
00016 }
00017 
00018 
00019 extern int test_in_mod2 (int (*mainp)(int, char **));
00020 int
00021 test_in_mod2 (int (*mainp)(int, char **))
00022 {
00023   int (*ifp) (void);
00024   void *p;
00025   int result = 0;
00026 
00027   /* Find function `main'.  */
00028   p = dlsym (RTLD_DEFAULT, "main");
00029   if (p == NULL)
00030     {
00031       printf ("%s: main not found\n", __FILE__);
00032       result = 1;
00033     }
00034   else if ((int (*)(int, char **))p != mainp)
00035     {
00036       printf ("%s: wrong address returned for main\n", __FILE__);
00037       result = 1;
00038     }
00039   else
00040     printf ("%s: main correctly found\n", __FILE__);
00041 
00042   ifp = dlsym (RTLD_DEFAULT, "found_in_mod1");
00043   if ((void *) ifp == NULL)
00044     {
00045       printf ("%s: found_in_mod1 not found\n", __FILE__);
00046       result = 1;
00047     }
00048   else if (ifp () != 1)
00049     {
00050       printf ("%s: wrong address returned for found_in_mod1\n", __FILE__);
00051       result = 1;
00052     }
00053   else
00054     printf ("%s: found_in_mod1 correctly found\n", __FILE__);
00055 
00056   ifp = dlsym (RTLD_DEFAULT, "found_in_mod2");
00057   if ((void *) ifp == NULL)
00058     {
00059       printf ("%s: found_in_mod2 not found\n", __FILE__);
00060       result = 1;
00061     }
00062   else if (ifp () != 2)
00063     {
00064       printf ("%s: wrong address returned for found_in_mod2\n", __FILE__);
00065       result = 1;
00066     }
00067   else
00068     printf ("%s: found_in_mod2 correctly found\n", __FILE__);
00069 
00070   return result;
00071 }