Back to index

glibc  2.9
dblload.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <mcheck.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 
00006 
00007 int
00008 main (void)
00009 {
00010   void *p1;
00011   void *p2;
00012   int (*fp) (void);
00013   int result;
00014 
00015   mtrace ();
00016 
00017   p1 = dlopen ("dblloadmod1.so", RTLD_LAZY);
00018   if (p1 == NULL)
00019     {
00020       printf ("cannot open dblloadmod1.so: %s\n", dlerror ());
00021       exit (EXIT_FAILURE);
00022     }
00023 
00024   p2 = dlopen ("dblloadmod2.so", RTLD_LAZY);
00025   if (p1 == NULL)
00026     {
00027       printf ("cannot open dblloadmod2.so: %s\n", dlerror ());
00028       exit (EXIT_FAILURE);
00029     }
00030 
00031   fp = dlsym (p1, "foo");
00032   if (fp == NULL)
00033     {
00034       printf ("cannot get function \"foo\": %s\n", dlerror ());
00035       exit (EXIT_FAILURE);
00036     }
00037 
00038   result = fp ();
00039 
00040   if (dlclose (p1) != 0)
00041     {
00042       printf ("error while closing dblloadmod1.so: %s\n", dlerror ());
00043       exit (EXIT_FAILURE);
00044     }
00045 
00046   if (dlclose (p2) != 0)
00047     {
00048       printf ("error while closing dblloadmod2.so: %s\n", dlerror ());
00049       exit (EXIT_FAILURE);
00050     }
00051 
00052   return result;
00053 }