blob: b107f33bc6c45872e42267fe88507fd787de9317 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include <stdio.h>
#include <err.h>
#include <dlfcn.h>
int main(int argc, const char *argv[]) {
int i;
#ifdef DISABLE_PLUGINS
sayhello();
#else
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);
}
#endif
return 0;
}
|