dl.c
changeset 0 7d3c07f8acfb
child 1 9ccc1574a367
equal deleted inserted replaced
-1:000000000000 0:7d3c07f8acfb
       
     1 #include <stdio.h>
       
     2 #include <dlfcn.h>
       
     3 #include <stdlib.h>
       
     4 #include "dl.h"
       
     5 
       
     6 void *get_original_function(const char *soname, const char *name)
       
     7 {
       
     8     const char* error;
       
     9     void *handle = dlopen(soname, RTLD_LAZY);
       
    10     void *rc;
       
    11 
       
    12     if (!handle) {
       
    13 	fprintf(stderr, "dlopen on %s: %s\n", soname, dlerror());
       
    14 	exit(1);
       
    15     }
       
    16 
       
    17     dlerror();
       
    18     rc = dlsym(handle, name);
       
    19     if ((error = dlerror())) {
       
    20 	fprintf(stderr, "dlsym for %s: %s\n", name, error);
       
    21 	exit(1);
       
    22     }
       
    23     dlclose(handle);
       
    24 
       
    25     return rc;
       
    26 }