aboutsummaryrefslogtreecommitdiffstats
path: root/loadgl.c.in
diff options
context:
space:
mode:
Diffstat (limited to 'loadgl.c.in')
-rw-r--r--loadgl.c.in48
1 files changed, 48 insertions, 0 deletions
diff --git a/loadgl.c.in b/loadgl.c.in
new file mode 100644
index 0000000..a76eebc
--- /dev/null
+++ b/loadgl.c.in
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2018 Tomasz Kramkowski <tk@the-tk.com>
+ * SPDX-License-Identifier: MIT
+ */
+#include <setjmp.h>
+
+#include "loadgl.h"
+
+#define LGL_FUNC(name, glname) \
+ name##_func *name; \
+ static const char *name##_gln = #glname;
+
+FUNCS()dnl
+
+static void *load_func(const char *name, lgl_loadfunc *load, jmp_buf env)
+{
+ void *ret;
+
+ ret = load(name);
+ if (ret == NULL)
+ longjmp(env, LGL_MISSING);
+
+ return ret;
+}
+
+enum lgl_status lgl_load(lgl_loadfunc *load)
+{
+ enum lgl_status status;
+ jmp_buf env;
+
+ status = setjmp(env);
+ if (status != 0)
+ return status;
+
+#define LGL_LOAD(name) name = (name##_func *)load_func(name##_gln, load, env);
+ LOADS()dnl
+
+ return LGL_OK;
+}
+
+const char *lgl_strerror(enum lgl_status status)
+{
+ switch (status) {
+ case LGL_OK: return "Success";
+ case LGL_MISSING: return "Missing function";
+ }
+ return "Unknown";
+}