From 6adfb65f6646537abb0ad717614eec26ff14761c Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 8 Jul 2024 09:45:14 -0400 Subject: Initial commit --- ext_internal.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 ext_internal.c (limited to 'ext_internal.c') diff --git a/ext_internal.c b/ext_internal.c new file mode 100644 index 0000000..3199eb7 --- /dev/null +++ b/ext_internal.c @@ -0,0 +1,46 @@ +// +// Created by jhunk on 7/2/24. +// +#include "ext_internal.h" +#include "extensions/ext.h" + +void asdfapi_ext_show_descriptor(struct ASDFExtension *info) { + printf("Extension name: %s\n", info->name); + printf("Extension description: %s\n", info->desc); +} + +void *asdfapi_ext_load(struct ASDFExtension **info, const char *filename) { + fnptr_ext_init ext_init; + + printf("Loading extension: %s\n", filename); + void *handle_ext = dlopen(filename, RTLD_LAZY); + if (handle_ext) { + dlerror(); + ext_init = dlsym(handle_ext, "asdfapi_ext_init"); + if (ext_init) { + (*ext_init)(); + dlerror(); + *info = dlsym(handle_ext, "asdfapi_ext_descriptor"); + if (!*info) { + fprintf(stderr, "error reading extension descriptor: %s\n", dlerror()); + goto fail; + } + } else { + fprintf(stderr, "error reading extension function: %s\n", dlerror()); + goto fail; + } + } else { + fprintf(stderr, "error opening extension: %s\n", dlerror()); + goto fail; + } + return handle_ext; + fail: + return NULL; +} + +void *asdfapi_ext_call(void *handle, const char *sym) { + const char *prefix = "asdfapi_ext_"; + char name[255] = {0}; + snprintf(name, sizeof(name) - 1, "%s%s", prefix, sym); + return dlsym(handle, name); +} -- cgit