aboutsummaryrefslogtreecommitdiff
path: root/arken/src/plugin_load.c
diff options
context:
space:
mode:
Diffstat (limited to 'arken/src/plugin_load.c')
-rw-r--r--arken/src/plugin_load.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/arken/src/plugin_load.c b/arken/src/plugin_load.c
new file mode 100644
index 0000000..6525969
--- /dev/null
+++ b/arken/src/plugin_load.c
@@ -0,0 +1,39 @@
+#include "plugin.h"
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+#include "plugin_exports.h"
+
+int load_plugin_from_dl_(dlhandle_t dl, plugin_t *plug)
+{
+ void *ptr;
+ int ret = 0;
+
+ const char **name = dlsym(dl, "plugin_name");
+ if (name) {
+ plug->plugin_name = *name;
+ }
+ else {
+ plug->plugin_name = NULL;
+ }
+
+ plug->state = NULL;
+ plug->library_handle = dl;
+
+#define LOAD_SYM(ret_type, sym, args) \
+ do { \
+ ptr = dlsym(dl, #sym); \
+ if (!ptr) { \
+ fprintf(stderr, "Plugin missing %s\n", #sym); \
+ ret |= 1; \
+ } \
+ plug->sym = (ret_type(*) args)ptr; \
+ } while (0);
+
+ MONTIS_PLUGIN_EXPORTS(LOAD_SYM);
+
+#undef LOAD_SYM
+
+ return ret;
+}