Select Git revision
module.pmod
-
Xavier Beaudouin authored
Rev: lib/modules/Protocols.pmod/LMTP.pmod:1.10 Rev: lib/modules/Protocols.pmod/SMTP.pmod/module.pmod:1.43
Xavier Beaudouin authoredRev: lib/modules/Protocols.pmod/LMTP.pmod:1.10 Rev: lib/modules/Protocols.pmod/SMTP.pmod/module.pmod:1.43
dynamic_load.c 6.62 KiB
#include "global.h"
#if !defined(HAVE_DLSYM) || !defined(HAVE_DLOPEN)
#undef HAVE_DLOPEN
#endif
#if !defined(HAVE_DLOPEN) && defined(HAVE_DLD_LINK) && defined(HAVE_DLD_GET_FUNC)
#define USE_DLD
#endif
#if 1
#if defined(HAVE_DLOPEN) || defined(USE_DLD)
#include "interpret.h"
#include "constants.h"
#include "error.h"
#include "module.h"
#include "stralloc.h"
#include "macros.h"
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#endif
#ifdef HAVE_DLD_H
#include <dld.h>
#endif
typedef void (*modfun)(void);
struct module_list
{
struct module_list * next;
void *module;
modfun init, exit;
};
struct module_list *dynamic_module_list = 0;
void f_load_module(INT32 args)
{
void *module;
modfun init, exit;
struct module_list *new_module;
const char *module_name;
if(sp[-args].type != T_STRING)
error("Bad argument 1 to load_module()\n");
module_name = sp[-args].u.string->str;
#ifdef HAVE_DLOPEN
#ifndef RTLD_NOW
#define RTLD_NOW 0
#endif
module=dlopen(module_name, RTLD_NOW);
if(!module)
{
error("load_module(\"%s\") failed: %s\n",
sp[-args].u.string->str, dlerror());
}
#elif defined(USE_DLD)
dld_create_reference("pike_module_init");
if (dld_link(module_name)) {
error("load_module(\"%s\") failed: %s\n",
module_name, dld_strerror(dld_errno));
}
module=strdup(module_name);
#endif /* HAVE_DLOPEN */