/* * linker.C: Abstraction of the dynamic linking system. * Rights to this code are documented in doc/pod/license.pod. * * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) */ static char const rcsid[] = "$Id: linker.C,v 1.4 2007/08/28 17:12:24 pippijn dead $"; #include "atheme.h" #include #ifdef __OpenBSD__ # define RTLD_NOW RTLD_LAZY #endif #ifndef __HPUX__ # define PLATFORM_SUFFIX ".so" #else # define PLATFORM_SUFFIX ".sl" #endif /* * linker_open() * * Inputs: * path to file to open * * Outputs: * linker handle. * * Side Effects: * a shared module is loaded into the application's memory space */ void * linker_open (char *path) { return dlopen (path, RTLD_NOW); } /* * linker_open_ext() * * Inputs: * path to file to open * * Outputs: * linker handle * * Side Effects: * the extension is appended if it's not already there. * a shared module is loaded into the application's memory space */ void * linker_open_ext (char *path) { void *handle; char *buf = static_cast (smalloc (strlen (path) + 20)); strlcpy (buf, path, strlen (path) + 20); if (!strstr (buf, PLATFORM_SUFFIX)) strlcat (buf, PLATFORM_SUFFIX, strlen (path) + 20); handle = linker_open (buf); free (buf); return handle; } /* * linker_getsym() * * Inputs: * linker handle, symbol to retrieve * * Outputs: * pointer to symbol, or NULL if no symbol. * * Side Effects: * none */ void * linker_getsym (void *vptr, char *sym) { return dlsym (vptr, sym); } /* * linker_close() * * Inputs: * linker handle * * Outputs: * none * * Side Effects: * the module is unloaded from the linker */ void linker_close (void *vptr) { dlclose (vptr); }