/* conveniences for casting and declarations */
typedef block_info* (*MM_CREATE)(size_t, MMPolicy);
typedef void* (*MM_ALLOCATE)(block_info *, size_t, char *);
typedef int (*MM_DEALLOCATE)(block_info *, void *);
typedef void (*MM_DESTROY)(block_info *);
/* Function pointers retrieved from the shared library */
typedef struct LibraryFunctions
{
   MM_CREATE create;
   MM_DESTROY destroy;
   MM_ALLOCATE allocate;
   MM_DEALLOCATE deallocate;
}LibraryFunctions;
/* Loads a shared library and returns a pointer to it in libhandle */
/* Returns SUCCESS, if it successful, otherwise, FAILURE           */
int load_library(const char *libname, void **libhandle)
{
*libhandle = dlopen(*libhandle, RTLD_LAZY);
if(!(*libhandle))
{
    return FAILURE;
}
else
{
    return SUCCESS;
}
return *libname;
}
int get_functions(void *libhandle, 
               LibraryFunctions *functions, 
               const char **fn_names)
{
functions->create = (MM_CREATE)(intptr_t)dlsym(libhandle, *fn_names);
if(!functions->create)
{
    return FAILURE;
}
                 
functions->destroy = (MM_DESTROY)(intptr_t)dlsym(libhandle, *fn_names);
if(!functions->destroy)
{
    return FAILURE;
}
functions->allocate = (MM_ALLOCATE)(intptr_t)dlsym(libhandle, *fn_names);
if(!functions->allocate)
{
    return FAILURE;
}
functions->deallocate = (MM_DEALLOCATE)(intptr_t)dlsym(libhandle, *fn_names);
if(!functions->deallocate)
{
    return FAILURE;
}
return SUCCESS;
 Here}
Here is part of the driver code to call the shared library: