Back to index

glibc  2.9
ltglobmod2.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 
00005 extern int bar (void);
00006 extern int foo (void);
00007 
00008 int
00009 foo (void)
00010 {
00011   void *h;
00012   int res;
00013 
00014   /* Load ltglobalmod1 in the global namespace.  */
00015   h = dlopen ("ltglobmod1.so", RTLD_GLOBAL | RTLD_LAZY);
00016   if (h == NULL)
00017     {
00018       printf ("%s: cannot open %s: %s",
00019              __FUNCTION__, "ltglobmod1.so", dlerror ());
00020       exit (EXIT_FAILURE);
00021     }
00022 
00023   /* Call bar.  This is undefined in the DSO.  */
00024   puts ("about to call `bar'");
00025   fflush (stdout);
00026   res = bar ();
00027 
00028   printf ("bar returned %d\n", res);
00029 
00030   dlclose (h);
00031 
00032   return res != 42;
00033 }