Back to index

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