blob: 1f132dfcce5e1d2881893b7826653d07ea9bce8e (
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
|
#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;
}
|