1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#define SHLIB_DYNLOAD
#define INTERNAL_CNAME_PATTERN "%s"
#define INTERNAL_FNAME_PATTERN "%s_" /**** check this */
#define VERBDFLT TRUE
LOCAL VOID link_and_load _((char *fname, char *libs, int fort));
LOCAL char *get_caddress _((char *name));
#include <dlfcn.h>
/**** This code ought to cache the addresses found, but I won't bother
until I revise the way dynamic loading works */
LOCAL VOID link_and_load(fname, libs, fort)
char *fname, *libs;
int fort;
{
static initialized = FALSE;
void *handle;
if (! initialized) {
setvalue(s_cfun_table, NIL);
initialized = TRUE;
}
handle = dlopen(fname, RTLD_LAZY);
if (handle == NULL) {
sprintf(buf, "can't open %s", fname);
xlfail(buf);
}
setvalue(s_cfun_table,
cons(cvfixnum((FIXTYPE) handle), getvalue(s_cfun_table)));
}
LOCAL char *get_caddress(name)
char *name;
{
LVAL next;
void *handle;
char *f;
static int initialized = FALSE;
static void *prog_handle = NULL;
for (next = getvalue(s_cfun_table); consp(next); next = cdr(next)) {
handle = (void *) getfixnum(car(next));
f = dlsym(handle, name);
if (f != NULL) return(f);
}
if (! initialized) {
prog_handle = dlopen(NULL, RTLD_LAZY);
initialized = TRUE;
}
f = dlsym(prog_handle, name);
return(f);
}
|