#include <dlf.h>
#include <errno.h>
#ifdef DLDAPI_DEFINED
#undef DLDAPI_DEFINED
#endif
#ifdef DLDAPI_SVR4_DLFCN
#define DLDAPI_DEFINED
static char sccsid[] = "@(#)dynamic load interface -- SVR4 dlfcn";
#endif
#ifdef DLDAPI_HP_SHL
#define DLDAPI_DEFINED
#include <dl.h>
static char sccsid[] = "@(#)dynamic load interface -- HP/UX dl(shl)";
void *
dlopen (char *path, int mode)
{
return (void *) shl_load ((char *) (path), BIND_IMMEDIATE | BIND_NONFATAL, 0L);
}
void *
dlsym (void *hdll, char *sym)
{
void *symaddr = 0;
int ret;
#if 0
if (!hdll)
hdll = (void *) PROG_HANDLE;
#endif
ret = shl_findsym ((shl_t *) & hdll, sym, TYPE_UNDEFINED, &symaddr);
if (ret == -1)
return 0;
return symaddr;
}
char *
dlerror ()
{
extern char *strerror ();
return strerror (errno);
}
int
dlclose (void *hdll)
{
struct shl_descriptor d;
if (shl_gethandle_r ((shl_t) hdll, &d) < 0 || d.ref_count > 1)
{
return 0;
}
return shl_unload ((shl_t) hdll);
}
#endif
#ifdef DLDAPI_AIX_LOAD
#define DLDAPI_DEFINED
#include <sys/types.h>
#include <sys/ldr.h>
#include <sys/stat.h>
#include <nlist.h>
#ifndef HTAB_SIZE
#define HTAB_SIZE 256
#endif
#define FACTOR 0.618039887
#ifndef ENTRY_SYM
#define ENTRY_SYM ".__start"
#endif
typedef struct slot_s
{
char *sym;
long fdesc[3];
struct slot_s *next;
}
slot_t;
typedef slot_t *hent_t;
typedef struct nlist nlist_t;
typedef struct stat stat_t;
typedef struct obj
{
int dev;
int ino;
char *path;
int (*pentry) ();
int refn;
hent_t htab[HTAB_SIZE];
struct obj *next;
}
obj_t;
static char *errmsg = 0;
static void
init_htab (hent_t * ht)
{
int i;
for (i = 0; i < HTAB_SIZE; i++)
ht[i] = (slot_t *) 0;
return;
}
static void
clean_htab (hent_t * ht)
{
int i;
slot_t *ent;
slot_t *tent;
for (i = 0; i < HTAB_SIZE; i++)
{
for (ent = ht[i]; ent;)
{
tent = ent->next;
free (ent->sym);
free (ent);
ent = tent;
}
ht[i] = 0;
}
return;
}
static int
hash (char *sym)
{
int a, key;
double f;
if (!sym || !*sym)
return 0;
for (key = *sym; *sym; sym++)
{
key += *sym;
a = key;
key = (int) ((a << 8) + (key >> 8));
key = (key > 0) ? key : -key;
}
f = key * FACTOR;
a = (int) f;
return (int) ((HTAB_SIZE - 1) * (f - a));
}
static hent_t
search (hent_t * htab, char *sym)
{
int key;
slot_t *ent;
key = hash (sym);
for (ent = htab[key]; ent; ent = ent->next)
{
if (!strcmp (ent->sym, sym))
return ent;
}
return 0;
}
static void
insert (hent_t * htab, slot_t * ent)
{
int key;
key = hash (ent->sym);
ent->next = htab[key];
htab[key] = ent;
return;
}
static slot_t *
slot_alloc (char *sym)
{
slot_t *ent;
ent = (slot_t *) malloc (sizeof (slot_t));
ent->sym = (char *) malloc (STRLEN (sym) + 1);
if (!ent->sym)
{
free (ent);
return 0;
}
STRCPY (ent->sym, sym);
return ent;
}
static obj_t *obj_list = 0;
void *
dlopen (char *file, int mode)
{
stat_t st;
obj_t *pobj;
char buf[1024];
if (!file || !*file)
{
errno = EINVAL;
return 0;
}
errno = 0;
errmsg = 0;
if (stat (file, &st))
return 0;
for (pobj = obj_list; pobj; pobj = pobj->next)
{
if (pobj->ino == st.st_ino
&& pobj->dev == st.st_dev)
{
pobj->refn++;
return pobj;
}
}
pobj = (obj_t *) malloc (sizeof (obj_t));
if (!pobj)
return 0;
pobj->path = (char *) malloc (STRLEN (file) + 1);
if (!pobj->path)
{
free (pobj);
return 0;
}
STRCPY (pobj->path, file);
pobj->dev = st.st_dev;
pobj->ino = st.st_ino;
pobj->refn = 1;
pobj->pentry = (int (*)()) load (file, 0, 0);
if (!pobj->pentry)
{
free (pobj->path);
free (pobj);
return 0;
}
init_htab (pobj->htab);
pobj->next = obj_list;
obj_list = pobj;
return pobj;
}
int
dlclose (void *hobj)
{
obj_t *pobj = (obj_t *) hobj;
obj_t *tpobj;
int match = 0;
if (!hobj)
{
errno = EINVAL;
return -1;
}
errno = 0;
errmsg = 0;
if (pobj == obj_list)
{
pobj->refn--;
if (pobj->refn)
return 0;
match = 1;
obj_list = pobj->next;
}
for (tpobj = obj_list; !match && tpobj; tpobj = tpobj->next)
{
if (tpobj->next == pobj)
{
pobj->refn--;
if (pobj->refn)
return 0;
match = 1;
tpobj->next = pobj->next;
}
}
if (match)
{
unload ((void *) (pobj->pentry));
clean_htab (pobj->htab);
free (pobj->path);
free (pobj);
}
return 0;
}
char *
dlerror ()
{
extern char *sys_errlist[];
if (!errmsg || !errmsg[0])
{
if (errno >= 0)
return sys_errlist[errno];
return "";
}
return errmsg;
}
void *
dlsym (void *hdl, char *sym)
{
nlist_t nl[3];
obj_t *pobj = (obj_t *) hdl;
slot_t *ent;
int (*fp) ();
long lbuf[3];
if (!hdl || !(pobj->htab) || !sym || !*sym)
{
errno = EINVAL;
return 0;
}
errno = 0;
errmsg = 0;
ent = search (pobj->htab, sym);
if (ent)
return ent->fdesc;
#define n_name _n._n_name
nl[0].n_name = ENTRY_SYM;
nl[1].n_name = sym;
nl[2].n_name = 0;
if (nlist (pobj->path, nl) == -1)
return 0;
if (!nl[0].n_type && !nl[0].n_value)
{
errmsg = "can't locate module entry symbol";
return 0;
}
if (!nl[1].n_type && !nl[1].n_value)
{
errmsg = "symbol does not exist in this module";
return 0;
}
ent = slot_alloc (sym);
if (!ent)
return 0;
insert (pobj->htab, ent);
memcpy (ent->fdesc, pobj->pentry, sizeof (ent->fdesc));
(ent->fdesc)[0] = (ent->fdesc)[0] +
(nl[1].n_value - nl[0].n_value);
return ent->fdesc;
}
#endif
#ifdef DLDAPI_WINDOWS
#define DLDAPI_DEFINED
#include <windows.h>
void *
dlopen (char * dll, int mode)
{
HINSTANCE hint;
if (dll == NULL)
{
return GetWindowWord (NULL, GWW_HINSTANCE);
}
hint = LoadLibrary (dll);
if (hint < HINSTANCE_ERROR)
{
return NULL;
}
return (void *) hint;
}
void *
dlsym (void * hdll, char * sym)
{
return (void *) GetProcAddress (hdll, sym);
}
char *
dlerror ()
{
return 0L;
}
int
dlclose (void * hdll)
{
FreeLibrary ((HINSTANCE) hdll);
}
#endif
#ifdef VMS
#define DLDAPI_DEFINED
#ifdef DLDAPI_VMS_IODBC
#include <stdio.h>
#include <descrip.h>
#include <starlet.h>
#include <ssdef.h>
#include <libdef.h>
#include <lib$routines>
#include <rmsdef.h>
#include <fabdef.h>
#include <namdef.h>
#ifndef LIB$M_FIS_MIXCASE
#define LIB$M_FIS_MIXCASE 1<<4
#endif
typedef struct
{
struct dsc$descriptor_s filename_d;
struct dsc$descriptor_s image_d;
char filename[NAM$C_MAXRSS];
}
dll_t;
static int saved_status = SS$_NORMAL;
static char dlerror_buf[256];
static int
iodbc_find_image_symbol (
struct dsc$descriptor_s *filename_d,
struct dsc$descriptor_s *symbol_d,
void **rp,
struct dsc$descriptor_s *image_d, int flag)
{
lib$establish (lib$sig_to_ret);
return lib$find_image_symbol (filename_d, symbol_d, rp, image_d, flag);
}
void *
iodbc_dlopen (char *path, int unused_flag)
{
int status;
dll_t *dll;
struct FAB imgfab;
struct NAM imgnam;
static char defimg[] = "SYS$SHARE:.EXE";
if (path == NULL)
{
saved_status = SS$_UNSUPPORTED;
return NULL;
}
dll = malloc (sizeof (dll_t));
if (dll == NULL)
{
saved_status = SS$_INSFMEM;
return NULL;
}
imgfab = cc$rms_fab;
imgfab.fab$l_fna = path;
imgfab.fab$b_fns = STRLEN (path);
imgfab.fab$w_ifi = 0;
imgfab.fab$l_dna = defimg;
imgfab.fab$b_dns = sizeof (defimg);
imgfab.fab$l_fop = FAB$M_NAM;
imgfab.fab$l_nam = &imgnam;
imgnam = cc$rms_nam;
imgnam.nam$l_esa = dll->filename;
imgnam.nam$b_ess = NAM$C_MAXRSS;
status = sys$parse (&imgfab);
if (!(status & 1))
{
free (dll);
saved_status = status;
return NULL;
}
dll->filename_d.dsc$b_dtype = DSC$K_DTYPE_T;
dll->filename_d.dsc$b_class = DSC$K_CLASS_S;
dll->filename_d.dsc$a_pointer = imgnam.nam$l_name;
dll->filename_d.dsc$w_length = imgnam.nam$b_name;
dll->image_d.dsc$b_dtype = DSC$K_DTYPE_T;
dll->image_d.dsc$b_class = DSC$K_CLASS_S;
dll->image_d.dsc$a_pointer = dll->filename;
dll->image_d.dsc$w_length = imgnam.nam$b_esl;
iodbc_dlsym (dll, "THIS_ROUTINE_MIGHT_NOT_EXIST");
if (!((saved_status ^ LIB$_KEYNOTFOU) & ~7))
{
saved_status = SS$_NORMAL;
}
if (saved_status & 1)
{
return dll;
}
else
{
free (dll);
return NULL;
}
}
void *
iodbc_dlsym (void *hdll, char *sym)
{
int status;
dll_t *dll;
struct dsc$descriptor_s symbol_d;
void *rp;
dll = hdll;
if (dll == NULL)
return NULL;
symbol_d.dsc$b_dtype = DSC$K_DTYPE_T;
symbol_d.dsc$b_class = DSC$K_CLASS_S;
symbol_d.dsc$a_pointer = sym;
symbol_d.dsc$w_length = STRLEN (sym);
status = iodbc_find_image_symbol (&dll->filename_d, &symbol_d, &rp,
&dll->image_d, 0);
if (!((saved_status ^ LIB$_KEYNOTFOU) & ~7))
{
status = iodbc_find_image_symbol (&dll->filename_d, &symbol_d, &rp,
&dll->image_d, LIB$M_FIS_MIXCASE);
}
if (status & 1)
{
return rp;
}
else
{
saved_status = status;
return NULL;
}
}
char *
iodbc_dlerror ()
{
struct dsc$descriptor desc;
short outlen;
int status;
if (saved_status & 1)
{
return NULL;
}
desc.dsc$b_dtype = DSC$K_DTYPE_T;
desc.dsc$b_class = DSC$K_CLASS_S;
desc.dsc$a_pointer = dlerror_buf;
desc.dsc$w_length = sizeof (dlerror_buf);
status = sys$getmsg (saved_status, &outlen, &desc, 15, 0);
if (status & 1)
{
dlerror_buf[outlen] = '\0';
}
else
{
sprintf (dlerror_buf, "Message number %8X", saved_status);
}
saved_status = SS$_NORMAL;
return (dlerror_buf);
}
int
iodbc_dlclose (void *hdll)
{
free (hdll);
return 0;
}
#endif
#endif
#ifdef DLDAPI_DYLD
#define DLDAPI_DEFINED
#include <stdio.h>
#include <mach-o/dyld.h>
static char sccsid[] = "@(#)dynamic load interface -- MacOS X dl(dyld)";
static void
undefined_symbol_handler (const char *symbolName)
{
fprintf (stderr, "dyld found undefined symbol: %s\n", symbolName);
abort ();
}
static NSModule
multiple_symbol_handler (NSSymbol s, NSModule old, NSModule new)
{
return (new);
}
static void
linkEdit_symbol_handler (NSLinkEditErrors c, int errorNumber,
const char *fileName, const char *errorString)
{
fprintf (stderr, "dyld errors during link edit for file %s\n%s\n",
fileName, errorString);
abort ();
}
void *
dlopen (char *path, int mode)
{
NSObjectFileImage image;
NSLinkEditErrorHandlers handlers;
NSModule handle = NULL;
int i;
handlers.undefined = undefined_symbol_handler;
#if !defined (NSLINKMODULE_OPTION_PRIVATE)
handlers.multiple = multiple_symbol_handler;
#endif
handlers.linkEdit = linkEdit_symbol_handler;
NSInstallLinkEditErrorHandlers (&handlers);
i = NSCreateObjectFileImageFromFile (path, &image);
if (i != NSObjectFileImageSuccess)
{
static char *ErrorStrings[] =
{
"%s(%d): Object Image Load Failure\n",
"%s(%d): Object Image Load Success\n",
"%s(%d): Not an recognizable object file\n",
"%s(%d): No valid architecture\n",
"%s(%d): Object image has an invalid format\n",
"%s(%d): Invalid access (permissions?)\n",
"%s(%d): Unknown error code from NSCreateObjectFileImageFromFile\n",
};
if (i < 0 || i > 6)
i = 6;
fprintf (stderr, ErrorStrings[i], path, i);
}
else
{
#if !defined (NSLINKMODULE_OPTION_PRIVATE)
handle = NSLinkModule (image, path, TRUE);
#else
handle = NSLinkModule (image, path, NSLINKMODULE_OPTION_PRIVATE);
#endif
}
return (void *) handle;
}
void *
dlsym (void *hdll, char *sym)
{
NSSymbol symbol;
#if !defined (NSLINKMODULE_OPTION_PRIVATE)
if (NSIsSymbolNameDefined (sym))
{
symbol = NSLookupAndBindSymbol (sym);
return NSAddressOfSymbol (symbol);
}
return NULL;
#else
symbol = NSLookupSymbolInModule ((NSModule) hdll, sym);
return NSAddressOfSymbol (symbol);
#endif
}
char *
dlerror ()
{
return NULL;
}
int
dlclose (void *hdll)
{
NSUnLinkModule (hdll, FALSE);
return 0;
}
#endif
#ifdef DLDAPI_MACX
static struct dlopen_handle *dlopen_handles = NULL;
static const struct dlopen_handle main_program_handle = { NULL };
static char *dlerror_pointer = NULL;
enum bool
{ false, true };
static enum bool
NSMakePrivateModulePublic (NSModule module)
{
static enum bool (*p) (NSModule module) = NULL;
if (p == NULL)
_dyld_func_lookup ("__dyld_NSMakePrivateModulePublic",
(unsigned long *) &p);
if (p == NULL)
{
#ifdef DEBUG
printf ("_dyld_func_lookup of __dyld_NSMakePrivateModulePublic "
"failed\n");
#endif
return (FALSE);
}
return (p (module));
}
void *
dlopen (char * path, int mode)
{
void *retval;
struct stat stat_buf;
NSObjectFileImage objectFileImage;
NSObjectFileImageReturnCode ofile_result_code;
NSModule module;
struct dlopen_handle *p;
unsigned long options;
NSSymbol NSSymbol;
void (*init) (void);
dlerror_pointer = NULL;
if (path == NULL)
{
retval = (void *) &main_program_handle;
return (retval);
}
if (stat (path, &stat_buf) == -1)
{
dlerror_pointer = strerror (errno);
return (NULL);
}
if ((mode & RTLD_UNSHARED) != RTLD_UNSHARED)
{
p = dlopen_handles;
while (p != NULL)
{
if (p->dev == stat_buf.st_dev && p->ino == stat_buf.st_ino)
{
if ((p->dlopen_mode & RTLD_UNSHARED) == RTLD_UNSHARED)
continue;
if ((p->dlopen_mode & RTLD_LOCAL) == RTLD_LOCAL &&
(mode & RTLD_GLOBAL) == RTLD_GLOBAL)
{
if (NSMakePrivateModulePublic (p->module) == TRUE)
{
p->dlopen_mode &= ~RTLD_LOCAL;
p->dlopen_mode |= RTLD_GLOBAL;
p->dlopen_count++;
return (p);
}
else
{
dlerror_pointer = "can't promote handle from "
"RTLD_LOCAL to RTLD_GLOBAL";
return (NULL);
}
}
p->dlopen_count++;
return (p);
}
p = p->next;
}
}
if ((mode & RTLD_NOLOAD) == RTLD_NOLOAD)
{
dlerror_pointer = "no existing handle for path RTLD_NOLOAD test";
return (NULL);
}
ofile_result_code = NSCreateObjectFileImageFromFile (path,
&objectFileImage);
if (ofile_result_code != NSObjectFileImageSuccess)
{
switch (ofile_result_code)
{
case NSObjectFileImageFailure:
dlerror_pointer = "object file setup failure";
return (NULL);
case NSObjectFileImageInappropriateFile:
dlerror_pointer = "not a Mach-O MH_BUNDLE file type";
return (NULL);
case NSObjectFileImageArch:
dlerror_pointer = "no object for this architecture";
return (NULL);
case NSObjectFileImageFormat:
dlerror_pointer = "bad object file format";
return (NULL);
case NSObjectFileImageAccess:
dlerror_pointer = "can't read object file";
return (NULL);
default:
dlerror_pointer = "unknown error from "
"NSCreateObjectFileImageFromFile()";
return (NULL);
}
}
options = NSLINKMODULE_OPTION_NONE |
NSLINKMODULE_OPTION_PRIVATE |
NSLINKMODULE_OPTION_RETURN_ON_ERROR;
if ((mode & RTLD_NOW) == RTLD_NOW)
options |= NSLINKMODULE_OPTION_BINDNOW;
module = NSLinkModule (objectFileImage, path, options);
NSDestroyObjectFileImage (objectFileImage);
if (module == NULL)
{
dlerror_pointer = "NSLinkModule() failed for dlopen()";
return (NULL);
}
if ((mode & RTLD_GLOBAL) == RTLD_GLOBAL)
{
if (NSMakePrivateModulePublic (module) == FALSE)
{
dlerror_pointer = "can't promote handle from RTLD_LOCAL to "
"RTLD_GLOBAL";
return (NULL);
}
}
p = malloc (sizeof (struct dlopen_handle));
if (p == NULL)
{
dlerror_pointer = "can't allocate memory for the dlopen handle";
return (NULL);
}
p->dev = stat_buf.st_dev;
p->ino = stat_buf.st_ino;
if (mode & RTLD_GLOBAL)
p->dlopen_mode = RTLD_GLOBAL;
else
p->dlopen_mode = RTLD_LOCAL;
p->dlopen_mode |= (mode & RTLD_UNSHARED) |
(mode & RTLD_NODELETE) | (mode & RTLD_LAZY_UNDEF);
p->dlopen_count = 1;
p->module = module;
p->prev = NULL;
p->next = dlopen_handles;
if (dlopen_handles != NULL)
dlopen_handles->prev = p;
dlopen_handles = p;
NSSymbol = NSLookupSymbolInModule (p->module, "__init");
if (NSSymbol != NULL)
{
init = NSAddressOfSymbol (NSSymbol);
init ();
}
return (p);
}
void *
dlsym (void * handle, char * symbol)
{
struct dlopen_handle *dlopen_handle, *p;
char symbol2[1024];
NSSymbol NSSymbol;
void *address;
symbol2[0] = '_';
strcpy (symbol2 + 1, symbol);
dlopen_handle = (struct dlopen_handle *) handle;
if (dlopen_handle == (struct dlopen_handle *) &main_program_handle)
{
if (NSIsSymbolNameDefined (symbol2) == TRUE)
{
NSSymbol = NSLookupAndBindSymbol (symbol2);
address = NSAddressOfSymbol (NSSymbol);
dlerror_pointer = NULL;
return (address);
}
else
{
dlerror_pointer = "symbol not found";
return (NULL);
}
}
p = dlopen_handles;
while (p != NULL)
{
if (dlopen_handle == p)
{
NSSymbol = NSLookupSymbolInModule (p->module, symbol2);
if (NSSymbol != NULL)
{
address = NSAddressOfSymbol (NSSymbol);
dlerror_pointer = NULL;
return (address);
}
else
{
dlerror_pointer = "symbol not found";
return (NULL);
}
}
p = p->next;
}
dlerror_pointer = "bad handle passed to dlsym()";
return (NULL);
}
char *
dlerror (void)
{
const char *p;
p = (const char *) dlerror_pointer;
dlerror_pointer = NULL;
return (char *)(p);
}
int
dlclose (void * handle)
{
struct dlopen_handle *p, *q;
unsigned long options;
NSSymbol NSSymbol;
void (*fini) (void);
dlerror_pointer = NULL;
q = (struct dlopen_handle *) handle;
p = dlopen_handles;
while (p != NULL)
{
if (p == q)
{
p->dlopen_count--;
if (p->dlopen_count != 0)
return (0);
NSSymbol = NSLookupSymbolInModule (p->module, "__fini");
if (NSSymbol != NULL)
{
fini = NSAddressOfSymbol (NSSymbol);
fini ();
}
options = 0;
if (p->dlopen_mode & RTLD_NODELETE)
options |= NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED;
if (p->dlopen_mode & RTLD_LAZY_UNDEF)
options |= NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES;
if (NSUnLinkModule (p->module, options) == FALSE)
{
dlerror_pointer = "NSUnLinkModule() failed for dlclose()";
return (-1);
}
if (p->prev != NULL)
p->prev->next = p->next;
if (p->next != NULL)
p->next->prev = p->prev;
if (dlopen_handles == p)
dlopen_handles = p->next;
free (p);
return (0);
}
p = p->next;
}
dlerror_pointer = "invalid handle passed to dlclose()";
return (-1);
}
#define DLDAPI_DEFINED
#endif
#ifdef DLDAPI_MAC
#include <CodeFragments.h>
#include <strconv.h>
static char *msg_error = NULL;
void *
dlopen (char *dll, int mode)
{
#ifdef __POWERPC__
CFragConnectionID conn_id;
Ptr main_addr;
Str255 name;
OSErr err;
if (dll == NULL)
{
msg_error = "Library name not valid.";
return NULL;
}
if ((err = GetSharedLibrary ((unsigned char *) str_to_Str255 (dll),
kPowerPCCFragArch, kLoadCFrag, &conn_id, &main_addr,
name)) != noErr)
{
msg_error = "Library cannot be loaded.";
return NULL;
}
msg_error = NULL;
return (void *) conn_id;
#else
CFragConnectionID conn_id;
Ptr main_addr;
Str255 name;
OSErr err;
if (dll == NULL)
{
msg_error = "Library name not valid.";
return NULL;
}
if ((err = GetSharedLibrary ((unsigned char *) str_to_Str255 (dll),
kMotorola68KCFragArch, kLoadCFrag, &conn_id, &main_addr,
name)) != noErr)
{
msg_error = "Library cannot be loaded.";
return NULL;
}
msg_error = NULL;
return (void *) conn_id;
#endif
}
void *
dlsym (void *hdll, char *sym)
{
#ifdef __POWERPC__
Ptr symbol;
CFragSymbolClass symbol_type;
OSErr err;
if (sym == NULL)
{
msg_error = "Symbol name not valid.";
return NULL;
}
if ((err =
FindSymbol ((CFragConnectionID) hdll,
(unsigned char *) str_to_Str255 (sym), &symbol,
&symbol_type)) != noErr)
{
msg_error = "Symbol cannot be loaded.";
return NULL;
}
msg_error = NULL;
return symbol;
#else
Ptr symbol;
CFragSymbolClass symbol_type;
if (sym == NULL)
{
msg_error = "Symbol name not valid.";
return NULL;
}
if (FindSymbol ((CFragConnectionID) hdll,
(unsigned char *) str_to_Str255 (sym), &symbol,
&symbol_type) != noErr)
{
msg_error = "Symbol cannot be loaded.";
return NULL;
}
msg_error = NULL;
return symbol;
#endif
}
char *
dlerror ()
{
return (msg_error) ? msg_error : "No error detected.";
}
int
dlclose (void *hdll)
{
#ifdef __POWERPC__
#else
if (CloseConnection ((CFragConnectionID *) hdll))
{
msg_error = "Library cannot be unloaded.";
return 1;
}
msg_error = NULL;
return 0;
#endif
}
#define DLDAPI_DEFINED
#endif
#ifdef DLDAPI_BE
#define DLDAPI_DEFINED
#include <kernel/image.h>
#include <be/support/Errors.h>
static char *msg_error = NULL;
void *
dlopen (char *dll, int mode)
{
image_id dll_id;
if (dll == NULL)
{
msg_error = "Library name not valid.";
return NULL;
}
dll_id = load_add_on (dll);
if (dll_id == B_ERROR)
{
msg_error = "Library cannot be loaded.";
return NULL;
}
msg_error = NULL;
return (void *) dll_id;
}
void *
dlsym (void *hdll, char *sym)
{
void *address = NULL;
if (sym == NULL)
{
msg_error = "Symbol name not valid.";
return NULL;
}
if (get_image_symbol ((image_id) hdll, sym, B_SYMBOL_TYPE_ANY,
&address) != B_OK)
{
msg_error = "Symbol cannot be loaded.";
return NULL;
}
msg_error = NULL;
return address;
}
char *
dlerror ()
{
return (msg_error) ? msg_error : "No error detected.";
}
int
dlclose (void *hdll)
{
if (unload_add_on ((image_id) hdll) != B_OK)
{
msg_error = "Library cannot be unloaded.";
return 1;
}
msg_error = NULL;
return 0;
}
#endif
#ifdef DLDAPI_OS2
#define DLDAPI_DEFINED
#endif
#ifdef DLDAPI_NEXT
#define DLDAPI_DEFINED
#endif
#ifndef DLDAPI_DEFINED
#error "dynamic load editor undefined"
#endif