Back to index

glibc  2.9
defaultmod1.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 
00012 extern int test_in_mod1 (int (*mainp)(int, char **));
00013 int
00014 test_in_mod1 (int (*mainp)(int, char **))
00015 {
00016   int (*ifp) (void);
00017   void *p;
00018   int result = 0;
00019 
00020   /* Find function `main'.  */
00021   p = dlsym (RTLD_DEFAULT, "main");
00022   if (p == NULL)
00023     {
00024       printf ("%s: main not found\n", __FILE__);
00025       result = 1;
00026     }
00027   else if ((int (*)(int, char **))p != mainp)
00028     {
00029       printf ("%s: wrong address returned for main\n", __FILE__);
00030       result = 1;
00031     }
00032   else
00033     printf ("%s: main correctly found\n", __FILE__);
00034 
00035   ifp = dlsym (RTLD_DEFAULT, "found_in_mod1");
00036   if ((void *) ifp == NULL)
00037     {
00038       printf ("%s: found_in_mod1 not found\n", __FILE__);
00039       result = 1;
00040     }
00041   else if (ifp () != 1)
00042     {
00043       printf ("%s: wrong address returned for found_in_mod1\n", __FILE__);
00044       result = 1;
00045     }
00046   else
00047     printf ("%s: found_in_mod1 correctly found\n", __FILE__);
00048 
00049   ifp = dlsym (RTLD_DEFAULT, "found_in_mod2");
00050   if ((void *) ifp == NULL)
00051     {
00052       printf ("%s: found_in_mod2 not found\n", __FILE__);
00053       result = 1;
00054     }
00055   else if (ifp () != 2)
00056     {
00057       printf ("%s: wrong address returned for found_in_mod2\n", __FILE__);
00058       result = 1;
00059     }
00060   else
00061     printf ("%s: found_in_mod2 correctly found\n", __FILE__);
00062 
00063   return result;
00064 }