diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-07-08 09:45:14 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-07-08 09:45:14 -0400 |
commit | 6adfb65f6646537abb0ad717614eec26ff14761c (patch) | |
tree | 1bbe40dd148313d3cd61ff22bd7b76852ad07102 /ext_internal.c | |
download | asdfapi-6adfb65f6646537abb0ad717614eec26ff14761c.tar.gz |
Initial commit
Diffstat (limited to 'ext_internal.c')
-rw-r--r-- | ext_internal.c | 46 |
1 files changed, 46 insertions, 0 deletions
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); +} |