aboutsummaryrefslogtreecommitdiff
path: root/include/LibraryLoader.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-09-28 01:03:06 +0200
committerdec05eba <dec05eba@protonmail.com>2022-09-28 01:03:06 +0200
commit1db22826831bf90f82422af5b5fa3d6caec32b77 (patch)
treefcf7f75e5a1cf114ebf277e522aa592feb699337 /include/LibraryLoader.hpp
parent2570d1e86adee7459ae0688fbe4d106e9567cb09 (diff)
Remove dependency on glew and glfw, move external files to external directory
Diffstat (limited to 'include/LibraryLoader.hpp')
-rw-r--r--include/LibraryLoader.hpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/include/LibraryLoader.hpp b/include/LibraryLoader.hpp
new file mode 100644
index 0000000..16dc580
--- /dev/null
+++ b/include/LibraryLoader.hpp
@@ -0,0 +1,38 @@
+#pragma once
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+typedef struct {
+ void **func;
+ const char *name;
+} dlsym_assign;
+
+static void* dlsym_print_fail(void *handle, const char *name, bool required) {
+ dlerror();
+ void *sym = dlsym(handle, name);
+ char *err_str = dlerror();
+
+ if(!sym)
+ fprintf(stderr, "%s: dlsym(handle, \"%s\") failed, error: %s\n", required ? "error" : "warning", name, err_str ? err_str : "(null)");
+
+ return sym;
+}
+
+/* |dlsyms| should be null terminated */
+static bool dlsym_load_list(void *handle, const dlsym_assign *dlsyms) {
+ bool success = true;
+ for(int i = 0; dlsyms[i].func; ++i) {
+ *dlsyms[i].func = dlsym_print_fail(handle, dlsyms[i].name, true);
+ if(!*dlsyms[i].func)
+ success = false;
+ }
+ return success;
+}
+
+/* |dlsyms| should be null terminated */
+static void dlsym_load_list_optional(void *handle, const dlsym_assign *dlsyms) {
+ for(int i = 0; dlsyms[i].func; ++i) {
+ *dlsyms[i].func = dlsym_print_fail(handle, dlsyms[i].name, false);
+ }
+} \ No newline at end of file