1 /*==============================================================================
2
3 $Id$
4
5 simple dlopen()-like implementation above HP-UX shl_xxx() API
6
7 Written by Miodrag Vallat <miod@mikmod.org>, released in the public domain
8
9 ==============================================================================*/
10
11 /*
12 * This implementation currently only works on hppa systems.
13 * It could be made working on m68k (hp9000s300) series, but my HP-UX 5.5
14 * disk is dead and I don't have the system tapes...
15 */
16
17 #ifdef HAVE_CONFIG_H
18 #include "config.h" /* const */
19 #endif
20
21 #ifdef MIKMOD_DLAPI_HP
22
23 #include <dl.h>
24 #include <malloc.h>
25 #include <string.h>
26
27 #include "dlfcn.h"
28
dlopen(const char * name,int flags)29 void *dlopen(const char *name, int flags)
30 {
31 shl_t handle;
32 char *library;
33
34 if (name == NULL || *name == '\0')
35 return NULL;
36
37 /* By convention, libmikmod will look for "foo.so" while on HP-UX the
38 name would be "foo.sl". Change the last letter here. */
39 library = MikMod_strdup(name);
40 library[strlen(library) - 1] = 'l';
41
42 handle = shl_load(library,
43 (flags & RTLD_LAZY ? BIND_DEFERRED : BIND_IMMEDIATE) | DYNAMIC_PATH,
44 0L);
45
46 MikMod_free(library);
47
48 return (void *)handle;
49 }
50
dlclose(void * handle)51 int dlclose(void *handle)
52 {
53 return shl_unload((shl_t)handle);
54 }
55
dlsym(void * handle,const char * sym)56 void *dlsym(void *handle, const char *sym)
57 {
58 shl_t h = (shl_t)handle;
59 void *address;
60
61 if (shl_findsym(&h, sym, TYPE_UNDEFINED, &address) == 0)
62 return address;
63 return NULL;
64 }
65
66 #endif
67 /* ex:set ts=4: */
68