diff options
Diffstat (limited to 'sayhello.c')
-rw-r--r-- | sayhello.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/sayhello.c b/sayhello.c new file mode 100644 index 0000000..1f132df --- /dev/null +++ b/sayhello.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <err.h> +#include <dlfcn.h> + +int main(int argc, const char *argv[]) { + int i; + if (argc < 2) + errx(1, "usage: sayhello PLUGIN..."); + + for (i=1; i<argc; i++) { + const char *plugin = argv[i]; + void (*sayhello)(void); + void *handle = dlopen(plugin, RTLD_NOW | RTLD_LOCAL); + + if (handle == NULL) { + warn("%s", plugin); + continue; + } + dlerror(); /* clear existing error */ + + /* get the "sayhello" function from plugin */ + sayhello = (void (*)(void)) dlsym(handle, "sayhello"); + sayhello(); + + dlclose(handle); + } + + return 0; +} |