forgot to commit the actual hostlib code
[tangerine.git] / arch / all-unix / hostlib / hostlib.c
blobae2f9a9f9e9c340bbc56745b9530f21414747578
1 #include <exec/types.h>
2 #include <aros/libcall.h>
4 #define timeval sys_timeval
5 #include <dlfcn.h>
6 #undef timeval
8 #include "hostlib_intern.h"
10 #include LC_LIBDEFS_FILE
12 #define DEBUG 0
13 #include <aros/debug.h>
15 AROS_LH2(void *, HostLib_Open,
16 AROS_LHA(const char *, filename, A0),
17 AROS_LHA(char **, error, A1),
18 struct HostLibBase *, HostLibBase, 1, HostLib) {
20 AROS_LIBFUNC_INIT
22 void *handle;
24 D(bug("[hostlib] Open: filename=%s\n", filename));
26 handle = dlopen((char *) filename, RTLD_NOW);
28 if (error != NULL)
29 *error = handle != NULL ? dlerror() : NULL;
31 return handle;
33 AROS_LIBFUNC_EXIT
36 AROS_LH2(int, HostLib_Close,
37 AROS_LHA(void *, handle, A0),
38 AROS_LHA(char **, error, A1),
39 struct HostLibBase *, HostLibBase, 2, HostLib) {
41 AROS_LIBFUNC_INIT
43 int ret;
45 D(bug("[hostlib] Close: handle=0x%08x\n", handle));
47 ret = dlclose(handle);
49 if (error != NULL)
50 *error = ret != 0 ? dlerror() : NULL;
52 return ret;
54 AROS_LIBFUNC_EXIT
57 AROS_LH3(void *, HostLib_GetPointer,
58 AROS_LHA(void *, handle, A0),
59 AROS_LHA(const char *, symbol, A1),
60 AROS_LHA(char **, error, A2),
61 struct HostLibBase *, HostLibBase, 3, HostLib) {
63 AROS_LIBFUNC_INIT
65 void *ptr;
67 D(bug("[hostlib] GetPointer: handle=0x%08x, symbol=%s\n", handle, symbol));
69 dlerror();
71 ptr = dlsym(handle, (char *) symbol);
73 if (error != NULL)
74 *error = dlerror();
76 return ptr;
78 AROS_LIBFUNC_EXIT