aboutsummaryrefslogtreecommitdiffstats
path: root/lib/src/util/windows/dlfcn.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/util/windows/dlfcn.c')
-rw-r--r--lib/src/util/windows/dlfcn.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/lib/src/util/windows/dlfcn.c b/lib/src/util/windows/dlfcn.c
new file mode 100644
index 000000000..5606074a0
--- /dev/null
+++ b/lib/src/util/windows/dlfcn.c
@@ -0,0 +1,73 @@
+/* dlfcn.c */
+
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <windows.h>
+
+static struct
+{
+ long lasterror;
+ const char *err_rutin;
+} var = { 0, NULL };
+
+void *
+dlopen (const char *filename, int flags)
+{
+ HINSTANCE hInst;
+
+ hInst = LoadLibrary (filename);
+ if (hInst == NULL)
+ {
+ var.lasterror = GetLastError ();
+ var.err_rutin = "dlopen";
+ }
+ return hInst;
+}
+
+int
+dlclose (void *handle)
+{
+ BOOL ok;
+ int rc = 0;
+
+ ok = FreeLibrary ((HINSTANCE) handle);
+ if (!ok)
+ {
+ var.lasterror = GetLastError ();
+ var.err_rutin = "dlclose";
+ rc = -1;
+ }
+ return rc;
+}
+
+void *
+dlsym (void *handle, const char *name)
+{
+ FARPROC fp;
+
+ fp = GetProcAddress ((HINSTANCE) handle, name);
+ if (!fp)
+ {
+ var.lasterror = GetLastError ();
+ var.err_rutin = "dlsym";
+ }
+ return (void *) (intptr_t) fp;
+}
+
+const char *
+dlerror (void)
+{
+ static char errstr[88];
+
+ if (var.lasterror)
+ {
+ snprintf (errstr, 88, "%s error #%ld", var.err_rutin, var.lasterror);
+ return errstr;
+ }
+ else
+ {
+ return NULL;
+ }
+} \ No newline at end of file